mirror of
https://github.com/apple/swift-numerics
synced 2026-11-24 04:38:11 +00:00
Merge pull request #352 from stephentyrone/fix-cosh-sinh-signs
Fix signs of cosh and sinh near the overflow boundary.
This commit is contained in:
2 files changed
+21
-3
No files matched your search
@@ -141,7 +141,10 @@ extension Complex: ElementaryFunctions {
|
||||
public static func cosh(_ z: Complex) -> Complex {
|
||||
guard z.isFinite else { return z }
|
||||
guard z.x.magnitude < -RealType.log(.ulpOfOne) else {
|
||||
let phase = Complex(RealType.cos(z.y), RealType.sin(z.y))
|
||||
let phase = Complex(
|
||||
RealType.cos(z.y),
|
||||
RealType(signOf: z.x, magnitudeOf: 1) * RealType.sin(z.y)
|
||||
)
|
||||
let firstScale = RealType.exp(z.x.magnitude/2)
|
||||
let secondScale = firstScale/2
|
||||
return phase.multiplied(by: firstScale).multiplied(by: secondScale)
|
||||
@@ -171,9 +174,12 @@ extension Complex: ElementaryFunctions {
|
||||
public static func sinh(_ z: Complex) -> Complex {
|
||||
guard z.isFinite else { return z }
|
||||
guard z.x.magnitude < -RealType.log(.ulpOfOne) else {
|
||||
let phase = Complex(RealType.cos(z.y), RealType.sin(z.y))
|
||||
let phase = Complex(
|
||||
RealType(signOf: z.x, magnitudeOf: RealType.cos(z.y)),
|
||||
RealType.sin(z.y)
|
||||
)
|
||||
let firstScale = RealType.exp(z.x.magnitude/2)
|
||||
let secondScale = RealType(signOf: z.x, magnitudeOf: firstScale/2)
|
||||
let secondScale = firstScale/2
|
||||
return phase.multiplied(by: firstScale).multiplied(by: secondScale)
|
||||
}
|
||||
return Complex(
|
||||
|
||||
Reference in new issue
Block a user