modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78
Xiao-Yong Jin <meta.jxy@gmail.com> once said: > modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 > modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 > modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 There was a fix to this on sources that was apparently never picked up by 9front. I've included it below but you can also find it in David du Colombier's mirror: https://github.com/0intro/plan9/commit/119c1d0c712512776162de1eca755006f07fe91c Cheers, Anthony diff --git a/sys/src/ape/lib/ap/plan9/frexp.c b/sys/src/ape/lib/ap/plan9/frexp.c --- a/sys/src/ape/lib/ap/plan9/frexp.c +++ b/sys/src/ape/lib/ap/plan9/frexp.c @@ -73,6 +73,16 @@ Cheat x; int e; + x.d = d; + e = (x.ms >> SHIFT) & MASK; + if(e == MASK){ + *ip = d; + if(x.ls != 0 || (x.ms & 0xfffffL) != 0) /* NaN */ + return d; + /* ±Inf */ + x.ms &= 0x80000000L; + return x.d; + } if(d < 1) { if(d < 0) { f = modf(-d, ip); @@ -82,8 +92,7 @@ *ip = 0; return d; } - x.d = d; - e = ((x.ms >> SHIFT) & MASK) - BIAS; + e -= BIAS; if(e <= SHIFT+1) { x.ms &= ~(0x1fffffL >> e); x.ls = 0;
We might need an isNaN check in there but it looks like we're also generating the wrong code for the <0 comparison. 6c emits UCOMISD followed by JCC. The UCOMISD will set all three ZF, PF, CF flags to 1 when either operand is NaN to indicate there is no ordering, but the JCC only looks at CF and incorrectly determines that NaN < 0.
> On Jan 21, 2021, at 10:20 PM, Anthony Martin <ality@pbrane.org> wrote: > > Xiao-Yong Jin <meta.jxy@gmail.com> once said: >> modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 >> modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 >> modf(ip=0x7fffffffe9e8,d=0xffffffffffffffff)+0x43 /sys/src/ape/lib/ap/plan9/frexp.c:78 > > There was a fix to this on sources that was > apparently never picked up by 9front. > > I've included it below but you can also find > it in David du Colombier's mirror: > > https://github.com/0intro/plan9/commit/119c1d0c712512776162de1eca755006f07fe91c The one at /sys/src/libc/port/frexp.c seems up-to-date with that, but not the ape one. I borrowed the one from musl https://git.musl-libc.org/cgit/musl/tree/src/math/modf.c to ape, which seems to behave better.
There is another ancient stray copy of modf /sys/src/ape/lib/ap/math/modf.c which is not in the mkfile.
you are correct. this fix has been applied previously to plan9 libc, but was missed the ape version. applied! thank you! -- cinap