bebbo / libnix

libnix (v4): a C link library for AmigaOS/m68k
14 stars 9 forks source link

printf issue with the 0x3f7fffff (0.9999...) floating point value #52

Closed BSzili closed 2 years ago

BSzili commented 2 years ago

The math version of printf seems to have trouble with the 0x3f7fffff floating point value, which equlals to 0.999999940395355224609. Instead of 1.000000 it gets interpreted as 0.1000000, the decimal point ends up in the wrong place. If I build without -noixemul the printf ixemul.library shows the correct value. The floattest.c program I created to reproduce this:

#include <stdio.h>

typedef union
{
    float f;
    unsigned int i;
} fi;

int main(void)
{
    volatile fi val;
    val.i = 0x3f7fffff; // 0.999999940395355224609
    printf("%f 0x%08x\n", val.f, val.i);
    return 0;
}

It can be built with m68k-amigaos-gcc -O2 -noixemul -m68020 -m68881 -o floattest floattest.c -lm. This is the minimal example with the exe: http://bszili.morphos.me/stuff/floattest.zip

BSzili commented 2 years ago

f950d9526e1d1c4989c9a07c1515f222f550558a appears to have fixed it, thanks!