Update Numeric.swift

// ------------------------------------------
// How to replicate the ** operator in Swift
//
This commit is contained in:
laurent b 2020-03-07 11:23:54 +01:00 committed by GitHub
parent 3701c108fd
commit bacb79f610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,3 +39,25 @@ func /<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
func /<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return lhs / F(rhs)
}
// ------------------------------------------
// How to replicate the ** operator in Swift
//
infix operator **
func **<I: BinaryInteger>(lhs: I, rhs: I) -> I {
return I(pow(Double(lhs), Double(rhs)))
}
func **<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: I, rhs: F) -> F {
return F(pow(Double(lhs),Double(rhs)))
}
func **<I: BinaryInteger, F: BinaryFloatingPoint>(lhs: F, rhs: I) -> F {
return F(pow(Double(lhs),Double(rhs)))
}
func **<F: BinaryFloatingPoint>(lhs: F, rhs: F) -> F {
return F(pow(Double(lhs),Double(rhs)))
}