Home » U++ Library support » U++ Core » FormatDouble and numbers under 1e-15
Re: FormatDouble and numbers under 1e-15 [message #25625 is a reply to message #25624] |
Thu, 04 March 2010 10:50   |
 |
koldo
Messages: 3435 Registered: August 2008
|
Senior Veteran |
|
|
rylek wrote on Thu, 04 March 2010 10:16 | 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
|
Hello Tomas
The comment comes from in FormatDouble() it is specified the number of digits, so if:
double num = 0.0000000000000001;
String str = FormatDouble(num, 0);
Now str = "1e-16".
As number of digits had to be 0, it seems the str would have to be just "0".
Best regards
IƱaki
|
|
|
Goto Forum:
Current Time: Tue May 13 23:10:38 CEST 2025
Total time taken to generate the page: 0.00653 seconds
|