Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Re: long->double->long goes negative
@ 2000-09-29 16:36 Brad Lucier
  0 siblings, 0 replies; 10+ messages in thread
From: Brad Lucier @ 2000-09-29 16:36 UTC (permalink / raw)
  To: axp-list

> 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.

Let me make a suggestion: when you post to this list, say what bothers
you explicitly.  Here, you don't seem to like how the Alpha kernel
implements behavior that is undefined according to the C standard; if
you had said this up front, then I wouldn't have replied, because there
is nothing sensible that I could have added.

Brad




^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: long->double->long goes negative
@ 2000-09-29 11:58 Rick Gorton
  2000-09-29 14:43 ` Uncle George
  0 siblings, 1 reply; 10+ messages in thread
From: Rick Gorton @ 2000-09-29 11:58 UTC (permalink / raw)
  To: 'axp-list@redhat.com'

I suggest that you peruse a copy of ieee754-1985, the ieee floating
point specification for a detailed description of why some of these
things can and do happen.  You're working on the edge cases of IEEE,
and those are fairly tricky.  A quick rule-of-thumb is that it is fair
to assume that any floating point value can vary by an amount equal to
the value of the least significant bit for any operation.

				/-- 0x7fffffff fffffffe
	0x7fffffff ffffffff
				\-- 0x80000000 00000000

				/-- 0x3fefffff ffffffff
	0x3ff00000 00000000
				\-- 0x3ff00000 00000001

		Input			Input + 0.0e0

There are other things which affect the result, such as an odd-even
when to add, and when not to.
Another thing you can look at is paranoia.c (from someplace on the net)
which I think has commentary in the code about what's happening.
Yeah, sometimes it's counter-intuitive.

	Rick




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: long->double->long goes negative
@ 2000-09-29  7:49 Phil Carmody
  0 siblings, 0 replies; 10+ messages in thread
From: Phil Carmody @ 2000-09-29  7:49 UTC (permalink / raw)
  To: axp-list

The correct answer is of course "Scott Nudds flies out of your nose" (comp.lang.c.moderated and comp.lang.asm.x86 reference frm years back)

<<<
An rvalue of a floating point type can be converted to an rvalue of an integer type.  The conversion truncates; that is, the fractional  part is discarded.  The behavior is undefined if the truncated value cannot be represented in the destination type.
>>>

_Undefined_ behaviour means that electrocuting the user is one of the other options. Just don't do it. If it formatted your hard disk that's because you invoked undefined behaviour. 

Phil
(with language lawyer hat on)

> >         lb =0x7fffffffffffffffL;
> >         db = (double) lb;
> >         la = (long) db;

Judge Lewis Kaplan's idiocy finally proved August 17, 2000:
"Defendants, on the other hand, are adherents of a movement
that believes that information should be available without
charge to anyone clever enough to break into the computer
systems or data storage media in which it is located."

_______________________________________________________________________

Free Unlimited Internet Access! Try it now! 
http://www.zdnet.com/downloads/altavista/index.html

_______________________________________________________________________




^ permalink raw reply	[flat|nested] 10+ messages in thread
* long->double->long goes negative
@ 2000-09-29  0:44 Uncle George
  2000-09-29  4:09 ` Brad Lucier
  0 siblings, 1 reply; 10+ messages in thread
From: Uncle George @ 2000-09-29  0:44 UTC (permalink / raw)
  To: axp-list

What is wrong with this picture: Somehow I expected a positive number &
a result like 0x7fffffffffffffffL
Am I expecting too much:   signed - floating point blues.

results are: lb=9223372036854775807,
                    db=(9.223372036854775808e+18, 43e0000000000000),
                    la=-9223372036854775808

main()
{
        long lb,la;
        double db,da;
        union { long    q;  double  d;  } u;
        lb =0x7fffffffffffffffL;
        db = (double) lb;
        la = (long) db;
        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






^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2000-09-29 16:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-09-29 16:36 long->double->long goes negative Brad Lucier
  -- strict thread matches above, loose matches on Subject: below --
2000-09-29 11:58 Rick Gorton
2000-09-29 14:43 ` Uncle George
2000-09-29  7:49 Phil Carmody
2000-09-29  0:44 Uncle George
2000-09-29  4:09 ` Brad Lucier
2000-09-29  9:41   ` Uncle George
2000-09-29  9:56     ` Dr. David Gilbert
2000-09-29 10:57       ` Uncle George
2000-09-29 11:55         ` Dr. David Gilbert

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