bug in dtoa
Status: Alpha
Brought to you by:
f4ecw
The correct way should be:
char dtoa( char aBuf, double aD )
{
double tmpTrunc = trunc( aD );
int tmpTruncInt = (int)tmpTrunc;
char tmpRes = itoa( aBuf, tmpTruncInt );
tmpRes++ = '.';
static const int biggestPowerOfTen = 1000000; // = pow( 10, LONG_DIGITS ); double tmpMantissa = ( tmpTruncInt >= 0 ) ? aD - tmpTrunc : tmpTrunc - aD; return uitoa( tmpRes, (int)( biggestPowerOfTen * tmpMantissa) );
}
There is still a small issue with rounding but on the original code the decimal portion was not being decoded.
Hi. This actually does not solve the entire issue with the dtoa here. Assuming your number is 3.04, the tmpMantissa will be 0.04. So biggestPowerOfTen * tmpMantissa will be 40000, and the result will be "3.40000"
Hi Nimrods
Thanks for your contribution.
Do you want to contribute this fix yourself to this project ?
Remi
That is an issue! The code needs to left zero pad. Sorry i haven't tested this code but it is starting point:
Last edit: Edwin Chen 2015-10-17
Thanks. I'll give it a try.