From: Andrew Duncan on
This looks correct:
>> Complex(1,1)**-1
=> Complex(Rational(1, 2), Rational(-1, 2))

But this does not; should be same answer:
>> 1/Complex(1,1)
=> Complex(0, -1)

A similar try gives same (wrong) answer:
>> Complex(1,0) / Complex(1,1)
=> Complex(0, -1)

What am I missing? Thanks!

Andrew
--
Posted via http://www.ruby-forum.com/.

From: Robert Dober on
On Mon, Jun 7, 2010 at 9:01 PM, Andrew Duncan <andrew.duncan(a)sonos.com> wrote:
> This looks correct:
>>> Complex(1,1)**-1
> => Complex(Rational(1, 2), Rational(-1, 2))
>
> But this does not; should be same answer:
>>> 1/Complex(1,1)
> => Complex(0, -1)
>
Correct on my box
ruby-1.9.1-p378 > 1/Complex(1,1)
=> 12-12i

which version do you have?

HTH
R.

--
The best way to predict the future is to invent it.
-- Alan Kay

From: Andrew Duncan on
I have ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]

BTW, I hope that was 1/2 - 1/2i in your post...

If this is a bug, it's pretty egregious.

Robert Dober wrote:
> On Mon, Jun 7, 2010 at 9:01 PM, Andrew Duncan <andrew.duncan(a)sonos.com>
> wrote:
>> This looks correct:
>>>> Complex(1,1)**-1
>> => Complex(Rational(1, 2), Rational(-1, 2))
>>
>> But this does not; should be same answer:
>>>> 1/Complex(1,1)
>> => Complex(0, -1)
>>
> Correct on my box
> ruby-1.9.1-p378 > 1/Complex(1,1)
> => 12-12i
>
> which version do you have?
>
> HTH
> R.

--
Posted via http://www.ruby-forum.com/.

From: Jean-Julien Fleck on
2010/6/7 Andrew Duncan <andrew.duncan(a)sonos.com>:
> I have ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
>
> BTW, I hope that was 1/2 - 1/2i in your post...
>
> If this is a bug, it's pretty egregious.

Seems to be a bug when both real and imaginary parts are integers:

>> require 'complex'
=> true
>> 1/Complex(1,1)
=> Complex(0, -1)
>> Complex(1,1)**(-1)
=> Complex(Rational(1, 2), Rational(-1, 2))
>> 1/Complex(1,0)
=> Complex(1, 0)
>> 1/Complex(1,0.5)
=> Complex(0.8, -0.4)
>> 1/Complex(1,1)
=> Complex(0, -1)
>> 1/Complex(1,2)
=> Complex(0, -1)
>> 1/Complex(1,3)
=> Complex(0, -1)
>> 1/Complex(1,4)
=> Complex(0, -1)
>> 1/Complex(1,4.4)
=> Complex(0.0491159135559921, -0.216110019646365)
>> 1/Complex(1,-1)
=> Complex(0, 0)
>> 1/Complex(1,-2)
=> Complex(0, 0)
>> 1/Complex(2,-2)
=> Complex(0, 0)
>> 1/Complex(2.2,-2)
=> Complex(0.248868778280543, 0.226244343891403)
>> 1/(Complex(1.0001,1.0001))
=> Complex(0.4999500049995, -0.4999500049995)

Brisingr ~>ruby -v
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]

Cheers,

--
JJ Fleck
PCSI1 Lycée Kléber

From: Andrew Duncan on
Interestingly, when I just use the Web interpreter from
http://TryRuby.org, I do get the correct result also:

>> 1/Complex(1,1)
=> ((1/2)-(1/2)*i)

Looks like a serious bug to me...
--
Posted via http://www.ruby-forum.com/.