phoenix-rtos / phoenix-rtos-project

Sample project using Phoenix-RTOS
https://phoenix-rtos.com
BSD 3-Clause "New" or "Revised" License
45 stars 32 forks source link

Strtod doesn't handle hex numbers floats #657

Open maska989 opened 1 year ago

maska989 commented 1 year ago

*Problem occurs when hex input float is used

Tested between ia32-generic and host-generic

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main(void)
{
    float f = 3.40282347e+38F;

    printf("printf =>\n%f || %a || %e || %g\n", f, f, f, f);

    printf("\nstrtod %%a=>\n%f ||", strtod("0x1.fffffe0000000p+127", NULL));
    printf(" %a ||", strtod("0x1.fffffe0000000p+127", NULL));
    printf(" %e ||", strtod("0x1.fffffe0000000p+127", NULL));
    printf(" %g\n", strtod("0x1.fffffe0000000p+127", NULL));

    printf("\nstrtod %%e=>\n%f ||", strtod("3.402823e+38", NULL));
    printf(" %a ||", strtod("3.402823e+38", NULL));
    printf(" %e ||", strtod("3.402823e+38", NULL));
    printf(" %g\n", strtod("3.402823e+38", NULL));

    printf("\nstrtod %%g=>\n%f ||", strtod("3.40282e+38", NULL));
    printf(" %a ||", strtod("3.40282e+38", NULL));
    printf(" %e ||", strtod("3.40282e+38", NULL));
    printf(" %g\n", strtod("3.40282e+38", NULL));
}
Darchiv commented 3 months ago

Applies to strtod(), strtof(), strtold()