Subject: Doing slightly advanced math in ruby

Author: Massaria

Posted: 01/29/2006 08:52AM

My needs in way of mathematical expressions have been in way of basic arithmetic so far, but now I find I need something that I just can't figure from the Math module alone.

I've always thought that ^ would multiply the preceeding number with itself a number of times equal to the following number (2^3 = 2*2*2 = 8). This is clearly not the case in ruby - I can't fathom where those results are coming from.

Mass,

a C- math student.

reply

Author: Massaria

Posted: 01/29/2006 08:52AM

My needs in way of mathematical expressions have been in way of basic arithmetic so far, but now I find I need something that I just can't figure from the Math module alone.

I've always thought that ^ would multiply the preceeding number with itself a number of times equal to the following number (2^3 = 2*2*2 = 8). This is clearly not the case in ruby - I can't fathom where those results are coming from.

Mass,

a C- math student.

reply

Subject: Doing slightly advanced math in ruby

Author: Tyche

Posted: 01/29/2006 09:19PM

Massaria wrote:

>

> I've always thought that ^ would multiply the preceeding number with itself a number of times equal to the following number (2^3 = 2*2*2 = 8). This is clearly not the case in ruby - I can't fathom where those results are coming from.

Hah. I hit this a couple months back and scoured the Math lib looking for the pow() function (ala C). Then I stumbled upon it...

2**3 => 8

works for floating point too..

2.0**3.3 => 9.84915530675933

^ is the XOR bit function

00000010 XOR 00000011 => 00000001

reply

Author: Tyche

Posted: 01/29/2006 09:19PM

Massaria wrote:

>

> I've always thought that ^ would multiply the preceeding number with itself a number of times equal to the following number (2^3 = 2*2*2 = 8). This is clearly not the case in ruby - I can't fathom where those results are coming from.

Hah. I hit this a couple months back and scoured the Math lib looking for the pow() function (ala C). Then I stumbled upon it...

2**3 => 8

works for floating point too..

2.0**3.3 => 9.84915530675933

^ is the XOR bit function

00000010 XOR 00000011 => 00000001

reply