apple / swift-numerics

Advanced mathematical types and functions for Swift
Apache License 2.0
1.68k stars 147 forks source link

Add complex log(onePlus:), update log() #155

Closed stephentyrone closed 3 years ago

stephentyrone commented 4 years ago

Adapts @NevinBR's cute factorization of the real part here:

https://forums.swift.org/t/elementaryfunctions-compliance-for-complex/37903/3

Adds a little bit of FMA magic to avoid catastrophic cancellation and recover a good componentwise error bound as well as an error bound in the complex norm.

stephentyrone commented 4 years ago

@NevinBR what would you prefer to be credited as in the comments?

stephentyrone commented 4 years ago

Note that this doesn't yet handle Re(z) ≈ -1 quite right. That's relatively easy to fix up, but I have some other work to do today, so it'll have to wait.

NevinBR commented 4 years ago

@NevinBR what would you prefer to be credited as in the comments?

I’d be a little surprised if I’m the first to create an implementation like this, but any of “Nevin”, “NevinBR”, or “Nevin B-R” would be fine.