Home » U++ Library support » U++ Core » FormatDouble and numbers under 1e-15
Re: FormatDouble and numbers under 1e-15 [message #25624 is a reply to message #25603] |
Thu, 04 March 2010 10:16   |
rylek
Messages: 79 Registered: November 2005
|
Member |
|
|
Hello!
Well, it depends. I wrote three formatting functions for doubles, FormatDoubleFix, FormatDoubleExp and FormatDouble. They are very loosely modelled after C printf formatting options %f, %e, and %g, respectively. Now as %g (FormatDouble) is supposed to automatically select between %f and %e, I employed the exponent check to use %f as a form of "optimization" or "user preferable" output for small absolute values of exponent. However whenever the exponent gets either too high or too low, formatting the number in fixed notation results in an unreasonably long string of zeroes. Keeping in mind the double's are floating points, for a number in the range, say, 1e-20, there are about 16 valid decimal digits 20 positions right of the decimal point, and to display such number as 0 is a complete loss of precision in my opinion. After all, printf("%g", 1e-20) also prints 1e-020 and not 0.
Regards
Tomas
|
|
|
Goto Forum:
Current Time: Tue May 13 23:15:32 CEST 2025
Total time taken to generate the page: 0.04193 seconds
|