> Interestingly, even though the fmod results are incorrect outside the
> -360 -> +360 range, the "incorrect" fmod results from a
> native-compiled program always come out at integer values.
When I first realized something was wrong in the Bifferboard's STL
generator I tried replicating the problem in many ways (because they
could be comming from many different places in the whole application)
and I had a hard time narrowing it down because the results seemed to
change as I tweeked the code to observe specific details. So I started
getting the impression that the problem changed everytime I compiled a
new executable, and even many of the 3D shapes produced by the STL
generator looked different in the STL viewer as I changed the code to
try and make the problem source manifest itself.
So I'm not sure but, although on a given executable the weirdness
seems to have some pattern and even be symetrical, it might depend on
memory configuration at the time of the calls, which could depend on
slight compilation changes produced while debugging. If true then it
would also explain you getting different results on different
environments. Also, I was trying to debug the problem on the
Bifferboard using release executables, which seem to lead to more even
variable results comparing to debug builds.
Anyway, to me it makes sense that the problem is all in the fmod and
that other functions are just suffering from it. If, for example, the
FPU emulator works by computing Taylor series expansion of the
trigonometric functions, then it makes sense that they needs to fix
the angles to some range and use fmod for that. For example,
internally it could work like
sin(a)=internal_taylor_series_expansion_of_sin(fmod(a, PI)) or
something like that. So, if fmod doesn't work correctly outside the
central range -modulus -> +modulus then all functions that depend on
it will also not work correctly outside their central range.
... actually when I noticed that sin, cos, and tan would only work
inside the -PI/2->+PI/2 range I fixed the angles by using - you
guessed it - fmod, and since that didn't solve the problem that meant
there had to be a problem with fmod, and I confirmed that by including
fmod in a subsequent test.
> IMHO your test program will be much more useful to "Linux types" if
> you make the following tweaks:
I followed your suggestions and if you don't define symbol XLS you get
a CSV file. I also changed the name of the file to "test_fpu.c", it is
a more convenient name for me than "mathtest.c", and it is definitly
better than the Code::Blocks-baptized "main.c".