Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Dec 2006 15:56:25 -0600
From:      crewman6@gmail.com
To:        freebsd-sparc64@freebsd.org
Subject:   Re: sparc64/107130: conversion from long double to long giving incorrect values
Message-ID:  <ae77fcae0612231356h75c5e7f2h49b53db4208ef49d@mail.gmail.com>
In-Reply-To: <9ca8670b0612231351u62a3daeav6161f10fcad87d3b@mail.gmail.com>
References:  <200612231450.kBNEoHeO070170@freefall.freebsd.org> <9ca8670b0612231351u62a3daeav6161f10fcad87d3b@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
>
>
> ---------- Forwarded message ----------
> From: Marius Strobl <marius@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@freebsd.org
>
> The following reply was made to PR sparc64/107130; it has been noted by
> GNATS.
>
> From: Marius Strobl <marius@alchemy.franken.de>
> To: Jim White <crewman6@gmail.com>
> Cc: freebsd-gnats-submit@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ae77fcae0612231356h75c5e7f2h49b53db4208ef49d>