UPDATE1
So after converting "+49.984367875E-230" to double and converting back to string, how can i print it as "4.998436788E-229" ?
As i have to convert "+49.984367875E-230" to double to do comparison.
I got a problem when converting string to double and double to string. For example:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char a[40]={"+49.984367875E-230"};
double d=atof(a);//d=4.9984367874999999e-229
char b[40],c[40];
sprintf(b,"%16.9E",d);
grisu2(c,"%16.9E",d);//implementation of grisu2 algorithm
printf("sprintf:%s\ngrisu2:%s\n",b,c);
return 0;
}
The result like this:
sprintf:4.998436787E-229
grisu2:4.998436788E-229
So, why the stdlib's atof
and sprintf
got the wrong result?
Since grisu2 is right, so i guess atof
is good, but sprintf
is wrong?
As i have grisu2, **so i want a faster and accurate atof
, I have searched the Internet and stackoverflow, but ** this fast_atof is not good.
I want something like grisu2, is there any paper or good implementation?