sparc64/107130: conversion from long double to long giving
incorrect values
crewman6 at gmail.com
crewman6 at gmail.com
Sat Dec 23 14:23:16 PST 2006
>
>
> ---------- Forwarded message ----------
> From: Marius Strobl <marius at alchemy.franken.de>
> Date: Dec 23, 2006 8:50 AM
> Subject: Re: sparc64/107130: conversion from long double to long giving
> incorrect values
> To: freebsd-sparc64 at freebsd.org
>
> The following reply was made to PR sparc64/107130; it has been noted by
> GNATS.
>
> From: Marius Strobl <marius at alchemy.franken.de>
> To: Jim White <crewman6 at gmail.com>
> Cc: freebsd-gnats-submit at freebsd.org
> Subject: Re: sparc64/107130: conversion from long double to long giving
> incorrect values
> Date: Sat, 23 Dec 2006 15:28:54 +0100
>
> 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);
>
>
After applying the patch, the conversion results in correct values.
More information about the freebsd-sparc64
mailing list