Re: Tough problem...



So it is not sin itself that is causing the problem

Actually the sin is believing that FP math can be accurate :)

I am not sure exactly how much is the reminder
function in this case more accurate. (It sure is faster than
the subtraction loop done by the FPU!)

1000/(2*Pi) can be rewritten as:

1000 * 1/(2*Pi)

And this means that after you computed 1/(2*Pi)
and then multiplied by 1000, you have cut off the last three decimal
places, because you moved the decimal point three places back.

The problem is equivalent to obtaining the
fractional part of a large number. The bigger the
number the less precision the fractional part has.

I noticed that, when I was doing:

a = i*x, 0<x<1
y = Frac(a);

As soon as I multipled x with i, I already lost three
decimal places in y, if i was 1000.

So, I was thinking that maybe there is way
to compute y, without explicitely computing a.

You should be permanently aware of the fact that the FPU does not use a
decimal representation, but a binary notation. Multiplication by 1000
is not really that simple in binary; 1024 for example is simpler.

Also note that Intel is simply implementing a standard (IEEE 754) doing
calculations differently might violate this, even if they provide more
accuracy (i don't know the details here).

--
The Fastcode Project: http://www.fastcodeproject.org/
.