Home » U++ Library support » U++ Core » U++ can't handle float to string and back for large numbers
|
|
|
Re: U++ can't handle float to string and back for large numbers [message #47768 is a reply to message #47765] |
Tue, 21 March 2017 21:35   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
I'm not IEEE expert, but why "exp = minmax<int>(ilog10(d), -308, +308);", I mean why decimal exp, when the native is binary, if I understand the IEEE format correctly. The whole code looks weird, all the computations instead of of working directly with bits, this will be very likely prone to some rounding/cutoffs artefacts. Also doing it directly from bits with decimal conversions only in the last phase would be probably faster, not just more accurate.
|
|
|
|
Re: U++ can't handle float to string and back for large numbers [message #47870 is a reply to message #47767] |
Sat, 15 April 2017 11:25   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
cbpporter wrote on Tue, 21 March 2017 10:52Still under investigation, but:
double normalize(double d, int& exp)
{
if(IsNull(d) || d == 0)
{
exp = Null;
return d;
}
bool sign = (d < 0);
if(sign) d = -d;
exp = minmax<int>(ilog10(d), -308, +308); // 8-byte double!
d /= ipow10(exp);
if(d >= 10) { d /= 10; exp++; }
if(d < 1) { d *= 10; exp--; }
return sign ? -d : d;
}
Looks like fixes the problem. This, and adding special case to suppress the inherent U++ IsNull mechanic. And some custom work to handle infinite better.
Thanks, fix applied. This code is ancient, I guess at that time, Tom has not considered handling 'exteremes' so important.
|
|
|
|
Goto Forum:
Current Time: Fri May 09 17:55:34 CEST 2025
Total time taken to generate the page: 0.00413 seconds
|