mirror of
https://github.com/apple/swift-numerics
synced 2026-11-30 05:28:47 +00:00
Further improvement to Complex.pow(_:Self,_:Self) edge cases.
Bring pow(zero, w) in line with the behavior of pow for the underlying real type.
This commit is contained in:
1 parent
89cfa62803
commit
60a3edbaa9
2 files changed
+9
-4
No files matched your search
@@ -413,16 +413,21 @@ extension Complex: ElementaryFunctions {
|
||||
}
|
||||
|
||||
// MARK: - pow-like functions
|
||||
/// `exp(w*log(z))`
|
||||
///
|
||||
/// Edge cases for this function are defined according to the defining
|
||||
/// expression exp(w log(z)), except that we define pow(0, w) to be 0
|
||||
/// instead of infinity when w is in the (strict) right half-plane, so that
|
||||
/// we agree with RealType.pow on the positive real line.
|
||||
@inlinable
|
||||
public static func pow(_ z: Complex, _ w: Complex) -> Complex {
|
||||
if z.isZero { return w.real > 0 ? zero : infinity }
|
||||
return exp(w * log(z))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public static func pow(_ z: Complex, _ n: Int) -> Complex {
|
||||
if z.isZero {
|
||||
return n < 0 ? .infinity : n == 0 ? .one : .zero
|
||||
}
|
||||
if z.isZero { return n < 0 ? infinity : n == 0 ? one : zero }
|
||||
// TODO: this implementation is not quite correct, because n may be
|
||||
// rounded in conversion to RealType. This only effects very extreme
|
||||
// cases, so we'll leave it alone for now.
|
||||
|
||||
Reference in new issue
Block a user