32bit vs. 64bit
Jason Riedy
jason at acm.org
Sat Mar 14 16:07:01 CDT 2009
And Sergei Steshenko writes:
> Well, it depends on what you're doing.
Amen.
Another fun example is to count how often sin(x).^2 + cos(x).^2
is not 1 for a given interval. Even if sin(x) and cos(x) are
correctly rounded, the result of sin(x).^2 + cos(x).^2 will not
always be 1. It's easiest to see in single:
> octave:1> x = single (0:2**-12:.5); length (x)
> ans = 2049
> octave:2> sum (sin (x).^2 + cos (x).^2 != 1)
> ans = 522
There is a method that gives better results in many situations.
Calculate intermediate results to higher precision, and then
round at points where you're storing some verifiable quantity.
This was the idea behind the 80-bit x87 registers, although it
was lost in the software shuffle.
In the sin(x).^2 + cos(x).^2 example, computing in double and
then rounding the result to single results in 1.
> octave:3> sum (single (sin (double (x)).^2 + cos (double (x)).^2) != 1)
> ans = 0
So adding single-precision support to Octave was a great thing,
and can produce *more* numerically sensible code. ;)
Jason
More information about the Bug-octave
mailing list