Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Uncle George <gatgul@voicenet.com>
To: axp-list@redhat.com
Subject: Re: long->double->long goes negative
Date: Fri, 29 Sep 2000 04:41:37 -0500	[thread overview]
Message-ID: <39D463D1.945DF157@voicenet.com> (raw)
In-Reply-To: 200009290409.XAA20223@polya.math.purdue.edu

so u expect +int -> +float -> -int  to be an A-OK situation. Gee what other
positive float numbers would u expect to give u negative results.

it should be either a 0, or a long.MAX value.  going neg ( or long.MIN ) is
not reasonable or rational
/gat

In my opinion, the results would be ok if it was converted to an unsigned
long. Then the high order bit would not be representative of a sign bit.


Brad Lucier wrote:

> Well, I don't find your posting very clear, but it doesn't seem
> that strange to me.  Perhaps I'm missing something.
>
> > main()
> > {
> >         long lb,la;
> >         double db,da;
> >         union { long    q;  double  d;  } u;
> >         lb =0x7fffffffffffffffL;
> >         db = (double) lb;
>
> db has only 53 bits mantissa, so lb cannot have all its 63 bits
> represented exactly, and on conversion lb is rounded to
> the nearest number, which happens to be 9.223372036854775808e+18
>
> >         la = (long) db;
>
> Here db does have an integral value, but that value is bigger than
> the largest long, so it can't be represented exactly as a long;
> the bit pattern of the converted result is  0x8000000000000000,
> which doesn't seem such a bad choice in this situation.
>
> >         u.d = db;
> >         printf("lb=%ld, db=(%23.18e, %lx), la=%ld\n", lb, db,u.q, la);
> > }
> >
> > cc -g -mieee a.c
> > ./a.out
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list




  reply	other threads:[~2000-09-29  9:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-29  0:44 long->double->long goes negative Uncle George
2000-09-29  4:09 ` Brad Lucier
2000-09-29  9:41   ` Uncle George [this message]
2000-09-29  9:56     ` Dr. David Gilbert
2000-09-29 10:57       ` Uncle George
2000-09-29 11:55         ` Dr. David Gilbert
  -- strict thread matches above, loose matches on Subject: below --
2000-09-29  7:49 Phil Carmody
2000-09-29 11:58 Rick Gorton
2000-09-29 14:43 ` Uncle George
2000-09-29 16:36 Brad Lucier
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox