apple / swift-numerics

Advanced mathematical types and functions for Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Floating point exponent `pow` returns NaN for integer exponents

PatrickPijnappel opened this issue · comments

Feel free to close if this is intentional, but currently the floating-point version of pow returns NaN for e.g. Double.pow(-1, 2.0), even though that's not complex. Shouldn't we be checking for Int(exactly: y) != nil? This appears to be the behavior of Darwin.pow(-1, 2.0).

public static func pow(_ x: Double, _ y: Double) -> Double {
    guard x >= 0 else { return .nan }
    return libm_pow(x, y)
}

@xwu Ah great that's what I was looking for. Makes sense, thank you.