NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-sparc64/47536: printf conversion fails for long double on sparc64



In article <20130207154009.746AE63EF83%www.NetBSD.org@localhost>,
Jukka Ruohonen  <gnats-bugs%NetBSD.org@localhost> wrote:
>The following reply was made to PR port-sparc64/47536; it has been noted
>by GNATS.
>
>From: Jukka Ruohonen <jruohonen%iki.fi@localhost>
>To: gnats-bugs%NetBSD.org@localhost
>Cc: 
>Subject: Re: port-sparc64/47536: printf conversion fails for long double
>on sparc64
>Date: Thu, 7 Feb 2013 17:12:27 +0200
>
> On Wed, Feb 06, 2013 at 02:35:01PM +0000, martin%NetBSD.org@localhost wrote:
> > This is a test program by Edward Berner posted to the Fossil users list:
> > 
> > #include <stdio.h>
> > 
> > int
> > main (int argc, char *argv[])
> > {
> >     long long n;
> >     long double ld;
> > 
> >     n = 2147483648LL;
> >     ld = n; 
> >     printf (" n = %lld\n", n);
> >     printf ("ld = %0.17Lg\n", ld);
> > 
> >     return 0;
> > }
> 
> Looks like a test case? Perhaps if augmented with some other comparable
> cases, similar problems in other architectures could be also revealed
> (cf. e.g. the innocent PR lib/22019; lib/32951; lib/44113).

The sign bit is not set in the long long -> long double conversion.
Printf is not at fault.

#include <stdio.h>
int
main(int argc, char *argv[])
{
        union {
                long double ld;
                long long n[2];
        } u;

        u.ld = 2147483648LL;
#ifdef __sparc64__
        u.n[1] = 0x0000000080000000llu;
#endif
        printf("%zu, %zu\n", sizeof(u.ld), sizeof(u.n));
        printf(" u.n %llx %llx\n", u.n[0], u.n[1]);
        printf("u.ld %0.17Lg\n", u.ld);
        return 0;
}

christos



Home | Main Index | Thread Index | Old Index