Forum: Ruby strange Complex behaviour

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8d6f5daee16e380ce0ac00395b417fb6?d=identicon&s=25 Schüle Daniel (Guest)
on 2006-03-08 00: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
irb(main):046:0>

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
81d609425e306219d54d793a0ad98bce?d=identicon&s=25 Matthew Moss (Guest)
on 2006-03-08 03: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.