rust-num / num-complex

Complex numbers for Rust
Apache License 2.0
232 stars 50 forks source link

Adapted complex exp() function so that it can handle inf and nan arguments as well #104

Closed JorisDeRidder closed 2 years ago

JorisDeRidder commented 2 years ago

Why this PR?

The current version of the complex exp() function is not able to handle arguments that contain +/- inf or NaN in their real or imaginary part. This impacts other complex functions that use the exp() function.

For example, for the most widely used implementation of the complex Faddeeva function w(), the current exp() implementation leads to w(1e160 - 1e159*i) = NaN + NaN *i , while the correct value is -5.586035480670854e-162 + 5.5860354806708545e-161 * i. The underlying reason is that the current exp() implementation erroneously returns exp(-inf + inf *i) = NaN + Nan *i instead of the correct 0 + 0*i.

Cf also issue #103.

Contents of this PR

cuviper commented 2 years ago
  • I added extra unit tests. The relevant values were taken from this page.

Could you please add that reference link as a comment in the test?

JorisDeRidder commented 2 years ago
  • I added extra unit tests. The relevant values were taken from this page.

Could you please add that reference link as a comment in the test?

OK. Done.

JorisDeRidder commented 2 years ago

A gentle reminder...

cuviper commented 2 years ago

bors r+

bors[bot] commented 2 years ago

Build succeeded: