Forum: Ruby strange Complex behaviour

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Schüle Daniel (Guest)
on 2006-03-08 01:56
(Received via mailing list)
Hello all,

I encountered a strange behaviour

irb(main):041:0* c = Complex(1.0,1.0)
=> Complex(1.0, 1.0)
irb(main):042:0> p = Complex.polar(2**0.5,45.0/360*2*PI)
=> Complex(1.0, 1.0)
irb(main):043:0> c == p
=> false
irb(main):044:0> c_ = Complex(1.0,1.0)
=> Complex(1.0, 1.0)
irb(main):045:0> c_ == c
=> true

I would strongly expect c and p to be equal
if c would be created from Fixnum's
than the result would be "explainable"
but still

irb(main):047:0* c = Complex(1,1)
=> Complex(1, 1)

Regards, Daniel
Matthew M. (Guest)
on 2006-03-08 04:03
(Received via mailing list)
Doesn't Complex hold floats?  Rounding errors?
Comparing float to float is tricksy business...
This topic is locked and can not be replied to.