How to use sin(_ : ) with a FloatingPoint value in Swift 3 [duplicate]
问题 This question already has answers here : Making Swift generics play with overloaded functions (2 answers) Closed last year . import Foundation public func sine <T: FloatingPoint > (_ x: T ) -> T{ return sin(x) } // Error: Cannot invoke 'sin' with an argument list of type '(T)' Is there a way around this? Many thanks. 回答1: You can make a sin method that accepts FloatingPoint type also as follow: import UIKit func sin<T: FloatingPoint>(_ x: T) -> T { switch x { case let x as Double: return sin