Did you try checking out the site archives? For example, yesterday someone asked a very similar question with An arithmetic oddity and a Super Search for precision yields a large number of results, and the first one (int($x) gives strange result) is a good discussion of exactly this issue.

Please read up on how floating point arithmatic works - for example What Every Computer Scientist Should Know About Floating-Point Arithmetic. I suspect that in C++ you are invoking the single precision cosine function (or maybe just the single-precision string format for output) and double precision in Java and Perl - doesn't it strike you as odd that it returns half as many digits? And I would like to know why you think any of those are more or less accurate - have you actually calculated the analytical answer? And what are you trying to do that requires 16 digits of precision - the Planck constant is only known to 8.

In short, what are you really trying to do? This sounds a lot like an XY Problem to me.


In reply to Re: cos (100000000.0) by kennethk
in thread cos (100000000.0) by kavehmz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.