We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guess is complex number math goes wrong in some cases:
require "complex" c1 = Complex.new 1, 0 c2 = Complex.new -1, 0 p c1 / c2 # => (NaN + NaNi)
(Nani?) :))
Actual result should be (-1 + 0i).
The text was updated successfully, but these errors were encountered:
Translated from npm package:
def /( other : Complex ) : Complex if zero? && other.zero? || abs2 == Float64::INFINITY && other.abs2 == Float64::INFINITY return Complex.new Float64::NAN, Float64::NAN end if abs2 == Float64::INFINITY || other.zero? return Complex.new Float64::INFINITY, Float64::INFINITY end if zero? || other.abs2 == Float64::INFINITY return Complex.zero end if other.imag.zero? return Complex.new real / other.real, imag / other.real end if other.real.abs < other.imag.abs m = other.real / other.imag n = other.real * m + other.imag Complex.new ( real * m + imag ) / n, ( imag * m - real ) / n else m = other.imag / other.real n = other.imag * m + other.real Complex.new ( real + imag * m ) / n, ( imag - real * m ) / n end end
That works well.
Sorry, something went wrong.
At least
crystal/src/complex.cr
Line 240 in dacd97b
if other.real <= other.imag
abs
real
image
No branches or pull requests
Guess is complex number math goes wrong in some cases:
(Nani?) :))
Actual result should be (-1 + 0i).
The text was updated successfully, but these errors were encountered: