in reply to cos (100000000.0)

Given the points about floating point numbers that other Monks have mentioned, there's a few points I'd like to raise:

Finally, my 64-bit perl running on AMD gives:

$ perl -le 'printf "%.55f\n", cos(100_000_000.0)' -0.3633850893556905270465051671635592356324195861816406250

Thus proving that Perl >> Java >> C++, AMD >> Intel and that Thursday is the new pink :-)

Replies are listed 'Best First'.
Re^2: cos (100000000.0)
by bart (Canon) on Sep 02, 2009 at 07:59 UTC
    Why are you taking the cosine of 100 million radians? I cannot think of any valid reason for doing that.

    Amen to that.

    To the OP: trigonometric functions are about the most unreliable calculations that you can do on a computer. I think it is just not reasonable to expect very precise results, for such a huge parameter value. Actually, the difference in results between the different implementations is a lot smaller, than I had anticipated.

    Floating point in Perl has about 15 significant digits. For a function like cos, the digits before the decimal point don't really matter, as you may just as well use the parameter value modulo 2*PI, and (ideally) expect the same outcome. That means that for this parameter, with 8 digits wasted, you have about 6-7 significant digits left. That is how close you may expect the result of the calculation of cos to be.

    I am guessing you just made that parameter up, as a silly test.