The output of MS's libc printf function is not unreasonable because it essentially gives you all 16 digits of precision correctly and then pads the rest with zeroes.
I pretty much agree with that assessment - though I believe it's actually rounding to 17 digits, not 16. (16 digits is not enough.)
However, it's a pity that MS doesn't provide the service offered by gcc.
I was hoping that someone would tell me that with MS toolchains there was a means of extracting the same behaviour, if only with toolchains beyond a certain version.
But, if that's not the case, then so be it.
It might actually be considered helpful for scientific applications because it correctly displays the digits of precision that you really have
I suppose that's how one would go about trying to present the behaviour as being desirable.
But, given that the value is a 53-bit integer (that doesn't exceed double precision), multiplied by a power of 2 (that doesn't exceed the maximum double exponent),
I see no harm in displaying the exact value of the double - as opposed to displaying a 17-digit value padded with sufficient zeroes that rounds to the same double.
To me, it's not a question of "right" and "wrong" - rather a question of "helpful" and "pointless".
The extreme case is that gcc provides:
C:\>perl -MPOSIX -e "printf '%.0f', POSIX::DBL_MAX;"
1797693134862315708145274237317043567980705675258449965989174768031572
+607800285387605895586327668781715404589535143824642343213268894641827
+684675467035375169860499105765512820762454900903893289440758685084551
+339423045832369032229481658085593321233482747978262041447231687381771
+80919299881250404026184124858368
whereas cl provides:
C:\Windows\System32>perl -MPOSIX -e "printf '%.0f', POSIX::DBL_MAX;"
1797693134862315700000000000000000000000000000000000000000000000000000
+000000000000000000000000000000000000000000000000000000000000000000000
+000000000000000000000000000000000000000000000000000000000000000000000
+000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000
Both values assign to the same double, but the former is an exact representation of that double, whereas the latter is an approximation.
Cheers,
Rob
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.