strange Complex behaviour

S

Schüle Daniel

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
 
M

Matthew Moss

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top