rust-num / num-complex

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

Cmplx division by 0 and NaN #5

Open cuviper opened 6 years ago

cuviper commented 6 years ago

From @rust-highfive on November 2, 2014 21:42

Issue by huonw Friday Apr 05, 2013 at 08:26 GMT

For earlier discussion, see https://github.com/rust-lang/rust/issues/5736

This issue was labelled with: A-libs, B-RFC, I-wrong in the Rust repository


Should 1/(0+0i) be NaN+NaN i or fail, or something else.

see also #1284

Copied from original issue: rust-num/num#20

cuviper commented 6 years ago

From @stygstra on June 19, 2015 19:1

There isn't much consensus among other languages:

shingtaklam1324 commented 6 years ago

Wolfram Alpha gives the answer of Complex infinity, which I think is more mathematically accurate, but not sure of the actual implementation.

In Golang's cmplx package, Complex infinity is represented as inf + inf i, and I can't find other implementations that specifically mention complex infinity.

thyrgle commented 5 years ago

I think that either an error or NaN is the best choice. From what I understand infinity is often introduced to compactify the space. In this case, adding infinity to the usual complex plane gives the Riemann Sphere. However, maybe some utility should be included to differentiate between standard and compacted spaces?

sourcefrog commented 2 years ago

I see that f64::recip gives inf (run) so it seems like it would be nice to be consistent with that, or at least to have one method that is consistent.