num-complex icon indicating copy to clipboard operation
num-complex copied to clipboard

Cmplx division by 0 and NaN

Open cuviper opened this issue 8 years ago • 4 comments

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 avatar Dec 19 '17 20:12 cuviper

From @stygstra on June 19, 2015 19:1

There isn't much consensus among other languages:

  • C++ and Racket agree when dividing by ±0.0±0.0i, but they differ when dividing by ±inf±infi.
  • Python rejects division by ±0.0±0.0i, gives NaN+NaNi when dividing by a complex number where both components are infinite, and gives ±0.0±0.0i when dividing by a complex number with exactly one infinite component.
  • Julia gives NaN+NaNi when dividing by ±0.0±0.0i and gives ±0.0±0.0i when dividing by a complex number where one or both of the components is infinite.

cuviper avatar Dec 19 '17 20:12 cuviper

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.

shingtaklam1324 avatar Feb 13 '18 10:02 shingtaklam1324

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?

thyrgle avatar Nov 19 '18 04:11 thyrgle

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.

sourcefrog avatar Jan 02 '22 19:01 sourcefrog