Conversions from long double to long and long long where the long double is a negative number always result in a value -1. This seems related to closed PR 55773, How-To-Repeat: #include <stdio.h> int main() { long double i; for (i=0;;i=i-1.0) printf("%Lf %d %ld %lld %f\n",i,(int)i,(long)i,(long long)i,(double)i); return 0; } Sample Output: 0.000000 0 0 0 0.000000 -1.000000 -1 -1 -1 -1.000000 -2.000000 -2 -1 -1 -2.000000 -3.000000 -3 -1 -1 -3.000000 -4.000000 -4 -1 -1 -4.000000 -5.000000 -5 -1 -1 -5.000000 -6.000000 -6 -1 -1 -6.000000 -7.000000 -7 -1 -1 -7.000000 -8.000000 -8 -1 -1 -8.000000 -9.000000 -9 -1 -1 -9.000000 -10.000000 -10 -1 -1 -10.000000
On Sat, Dec 23, 2006 at 07:54:11AM +0000, Jim White wrote: > > >How-To-Repeat: > #include <stdio.h> > int main() > { > long double i; > for (i=0;;i=i-1.0) > printf("%Lf %d %ld %lld %f\n",i,(int)i,(long)i,(long long)i,(double)i); > return 0; > } > > Sample Output: > 0.000000 0 0 0 0.000000 > -1.000000 -1 -1 -1 -1.000000 > -2.000000 -2 -1 -1 -2.000000 > -3.000000 -3 -1 -1 -3.000000 > -4.000000 -4 -1 -1 -4.000000 > -5.000000 -5 -1 -1 -5.000000 > -6.000000 -6 -1 -1 -6.000000 > -7.000000 -7 -1 -1 -7.000000 > -8.000000 -8 -1 -1 -8.000000 > -9.000000 -9 -1 -1 -9.000000 > -10.000000 -10 -1 -1 -10.000000 > This appears to be caused by a typo in the FPU emulation code. Could you please give the patch below a try (after applying re-compile and re-install libc, if you're linking your application statically re-compile it afterwards, too)? Marius Index: fpu_implode.c =================================================================== RCS file: /usr/data/bsd/cvs/fbsd/src/lib/libc/sparc64/fpu/fpu_implode.c,v retrieving revision 1.6 diff -u -r1.6 fpu_implode.c --- fpu_implode.c 28 Jul 2004 05:41:05 -0000 1.6 +++ fpu_implode.c 23 Dec 2006 14:20:13 -0000 @@ -277,7 +277,7 @@ if (i >= ((u_int64_t)0x8000000000000000LL + sign)) break; if (sign) - i = -1; + i = -i; res[1] = (int)i; return (i >> 32);
marius 2006-12-24 22:24:39 UTC FreeBSD src repository Modified files: lib/libc/sparc64/fpu fpu_implode.c Log: Fix a typo in __fpu_ftox() that caused long double to long (and long long) conversion of negative numbers to always result in -1. While at it, rearrange the nearby comment so it fits in 80 chars per line, like the rest of this file does. PR: 107130 MFC after: 1 day Revision Changes Path 1.7 +10 -9 src/lib/libc/sparc64/fpu/fpu_implode.c _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
marius 2006-12-26 09:45:19 UTC FreeBSD src repository Modified files: (Branch: RELENG_6) lib/libc/sparc64/fpu fpu_implode.c Log: MFC: 1.7 Fix a typo in __fpu_ftox() that caused long double to long (and long long) conversion of negative numbers to always result in -1. While at it, rearrange the nearby comment so it fits in 80 chars per line, like the rest of this file does. PR: 107130 Revision Changes Path 1.6.8.1 +10 -9 src/lib/libc/sparc64/fpu/fpu_implode.c _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
marius 2006-12-28 18:26:02 UTC FreeBSD src repository Modified files: (Branch: RELENG_6_2) lib/libc/sparc64/fpu fpu_implode.c Log: MFC: 1.7 (1.6.8.1) Fix a typo in __fpu_ftox() that caused long double to long (and long long) conversion of negative numbers to always result in -1. While at it, rearrange the nearby comment so it fits in 80 chars per line, like the rest of this file does. PR: 107130 Approved by: re (bmah) Committed from: 23C3 Revision Changes Path 1.6.16.1 +10 -9 src/lib/libc/sparc64/fpu/fpu_implode.c _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
State Changed From-To: open->closed Close; this problem was fixed in HEAD, RELENG_6 and RELENG_6_2.