Merge pull request #2 from multitudes/multitudes-patch--operator

Update Numeric.swift
This commit is contained in:
laurent b 2020-03-07 11:26:58 +01:00 committed by GitHub
commit 5708634d06
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)))
}