math changes from 1.8.1 to 1.8.2?

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
 
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

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
 
H

H.Yamamoto

Hello.

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?
 
P

Phil Tomson

Hello.

(e-mail address removed) (Phil Tomson) wrote:
(2005/02/08 19:00)



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
 
H

H.Yamamoto

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.

Sorry, I don't have G4 machine (and none of mac machines), so I cannot reproduce
problem from entire application. I thought if FixedPt is simple enough, I could
guess problem from its source code.

# I suspected lack of precision at first. Conversion String <=> Float may not be
# acculate enough in current ruby implementation. [ruby-talk:69518]
 
H

H.Yamamoto

Hello.

Maybe I misunderstood. I thought FixedPt is created for reproducing the problem,
but "floating point problem" and "FixedPt" might be totally different story ...
 
P

Phil Tomson

(e-mail address removed) (Phil Tomson) wrote:
(2005/02/09 23:00)


Sorry, I don't have G4 machine (and none of mac machines), so I cannot reproduce
problem from entire application. I thought if FixedPt is simple enough, I could
guess problem from its source code.

FixedPt is only part of the system. The FixedPt class allows simulation
of fixed point arithmetic. If you define:

fp = FixedPt.new(2.5,4,2)

You end up with:
fp.raw #=> 10 the raw value

which is 1010 in binary. considering that the binary point is at bit 2,
you have:

10.10 in binary, which is 2.5 in decimal.
# I suspected lack of precision at first. Conversion String <=> Float may not be
# acculate enough in current ruby implementation. [ruby-talk:69518]

I do some String -> Float conversion when I read in values from a file
(using scanf) but after that there are no such conversions. If that were
the problem, I suspect I would have seen it much earlier when I was doing
full floating point calculations. I suspect a difference in the hardware since
it runs fine on a Pentium IV machine, but fails on G4. It's not totally
unexpected since I'm dealing with some very small values in some cases,
and these very small values get summed together many times to determine an
outcome - so even small errors can be magnified.

Phil
 

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,780
Messages
2,569,607
Members
45,240
Latest member
pashute

Latest Threads

Top