P
Phil Tomson
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
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