[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

strange Complex behaviour

Daniel Schüle

3/7/2006 11:51:00 PM

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

1 Answer

matthew.moss.coder

3/8/2006 2:03:00 AM

0

Doesn't Complex hold floats? Rounding errors?
Comparing float to float is tricksy business...