f



math changes from 1.8.1 to 1.8.2?

I've got some code that does simulated fixed-point math and things like 
exp(-x).  I find that my simulations work fine on a Windows XP box, 
Pentium IV, Ruby 1.8.2.  However, when I run the same exact Ruby code on my 
Powerbook G4 running Ruby 1.8.1 I get lots of errors from my unit tests.

I suspect that what I'm doing is really stressing the floating point 
operations so it could just be a difference between the G4 and Pentium 
FPUs, but I'm also wondering if there were changes between Ruby 1.8.1 and 
Ruby 1.8.2 that might account for this (even changes to the way Bignum 
works, might account for it).  I'll load up Ruby 1.8.2 on the Powerbook 
tonight to see if that makes any difference...


For the curious, I created a class called FixedPt which allows you 
simulate fixed point math (useful for hardware design).  So you can do 
things like:

fp = FixedPt.new(Math.exp(-5),18,18)

Which defines an 18bit register with the binary point at bit 18 and stuffs 
the result of Math.exp(-5) into it (shifting the result to the left 18 
times).

fp.to_f #=> 0.00673675537109375
fp.raw  #=> 1766  
fp.to_i #=> 0


Phil

0
ptkwt (713)
2/7/2005 10:59:33 AM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

3 Replies
692 Views

Similar Articles

[PageSpeed] 2

In article <cu7hml01e9n@enews2.newsguy.com>,
Phil Tomson <ptkwt@aracnet.com> wrote:
>
>I've got some code that does simulated fixed-point math and things like 
>exp(-x).  I find that my simulations work fine on a Windows XP box, 
>Pentium IV, Ruby 1.8.2.  However, when I run the same exact Ruby code on my 
>Powerbook G4 running Ruby 1.8.1 I get lots of errors from my unit tests.
>
>I suspect that what I'm doing is really stressing the floating point 
>operations so it could just be a difference between the G4 and Pentium 
>FPUs, but I'm also wondering if there were changes between Ruby 1.8.1 and 
>Ruby 1.8.2 that might account for this (even changes to the way Bignum 
>works, might account for it).  I'll load up Ruby 1.8.2 on the Powerbook 
>tonight to see if that makes any difference...
>
>
>For the curious, I created a class called FixedPt which allows you 
>simulate fixed point math (useful for hardware design).  So you can do 
>things like:
>
>fp = FixedPt.new(Math.exp(-5),18,18)
>
>Which defines an 18bit register with the binary point at bit 18 and stuffs 
>the result of Math.exp(-5) into it (shifting the result to the left 18 
>times).
>
>fp.to_f #=> 0.00673675537109375
>fp.raw  #=> 1766  
>fp.to_i #=> 0
>
>

a followup....

I loaded up 1.8.2 on my powerbook last night and had the same problem 
(which doesn't exist on the Pentium IV).  I suspect it's a difference in 
the FPU between the G4 and PIV.  I'm doing lots of summations and 
conversions between floating point and fixed point, so I suspect it's the 
fault of the G4's FPU..... unless someone else has any other theories.

At any rate, it doesn't seem to be some difference in Ruby versions.

Phil


0
ptkwt (713)
2/8/2005 9:35:20 AM
Hello.

ptkwt@aracnet.com (Phil Tomson) wrote:
(2005/02/08 19:00)

>>fp = FixedPt.new(Math.exp(-5),18,18)
>>
>>Which defines an 18bit register with the binary point at bit 18 and stuffs 
>>the result of Math.exp(-5) into it (shifting the result to the left 18 
>>times).
>>
>>fp.to_f #=> 0.00673675537109375
>>fp.raw  #=> 1766  
>>fp.to_i #=> 0

>I loaded up 1.8.2 on my powerbook last night and had the same problem 
>(which doesn't exist on the Pentium IV).  I suspect it's a difference in 
>the FPU between the G4 and PIV.  I'm doing lots of summations and 
>conversions between floating point and fixed point, so I suspect it's the 
>fault of the G4's FPU..... unless someone else has any other theories.

Interesting. Can I see the code of FixedPt?



0
ocean8708 (34)
2/9/2005 2:40:25 AM
In article <20050209114012.F3646D50.ocean@m2.ccsnet.ne.jp>,
H.Yamamoto <ocean@m2.ccsnet.ne.jp> wrote:
>Hello.
>
>ptkwt@aracnet.com (Phil Tomson) wrote:
>(2005/02/08 19:00)
>
>>>fp = FixedPt.new(Math.exp(-5),18,18)
>>>
>>>Which defines an 18bit register with the binary point at bit 18 and stuffs 
>>>the result of Math.exp(-5) into it (shifting the result to the left 18 
>>>times).
>>>
>>>fp.to_f #=> 0.00673675537109375
>>>fp.raw  #=> 1766  
>>>fp.to_i #=> 0
>
>>I loaded up 1.8.2 on my powerbook last night and had the same problem 
>>(which doesn't exist on the Pentium IV).  I suspect it's a difference in 
>>the FPU between the G4 and PIV.  I'm doing lots of summations and 
>>conversions between floating point and fixed point, so I suspect it's the 
>>fault of the G4's FPU..... unless someone else has any other theories.
>
>Interesting. Can I see the code of FixedPt?

To see the problem, I suspect you'll need more than the FixedPt class.  
You'll probably also need the entire application.  It's a support vector 
machine implementation (kind of like a neural network). I could send it to 
you in a tar file if you wish.

Phil
0
ptkwt (713)
2/9/2005 1:35:26 PM
Reply: