Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* is this feature documented?
@ 2002-12-02 23:36 Andrew A. Gill
  2002-12-03  0:08 ` Kelledin
  2002-12-03  7:36 ` Falk Hueffner
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew A. Gill @ 2002-12-02 23:36 UTC (permalink / raw)
  To: AXP-list

I was working with Kai Sterker (well, asking for help) on a floating 
point exception in the Adonthell program, when she noticed this 
interesting feature: 

	[superluser@trystero superluser]$ cat fpe.cc 
	#include <stdio.h>

	    int main(void)
	    {
	      int x = (int) (4/(float)0);
	      printf ("x = %i\n", x);
	    }

	[superluser@trystero superluser]$ g++ fpe.cc 
	fpe.cc: In function `int main()':
	fpe.cc:5: warning: division by zero in `4 / 0.'
	[superluser@trystero superluser]$ ./a.out 
	x = 0

This is gcc version 3.2 20021115 (Red Hat Linux 8.0 3.2-14).  Should 
this be normal behavior?  Is this the expected output of standard C++?

-- 
|Andrew A. Gill                       |I posted to Silent-Tristero and|
|<superluser@mail.rit.edu>            |all I got was this stupid sig! |
|alt.tv.simpsons CBG-FAQ author       |                               |
|                          (Report all obscene mail to Le Maitre Pots)|
|Nothing here yet: <http://www.needsfoodbadly.com>    Temporary sig: --

Could be less broken...




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

* Re: is this feature documented?
  2002-12-02 23:36 is this feature documented? Andrew A. Gill
@ 2002-12-03  0:08 ` Kelledin
  2002-12-03  8:20   ` Andrew A. Gill
  2002-12-03  7:36 ` Falk Hueffner
  1 sibling, 1 reply; 4+ messages in thread
From: Kelledin @ 2002-12-03  0:08 UTC (permalink / raw)
  To: axp-list

On Monday 02 December 2002 05:36 pm, Andrew A. Gill wrote:
> I was working with Kai Sterker (well, asking for help) on a
> floating point exception in the Adonthell program, when she
> noticed this interesting feature:
>
> 	[superluser@trystero superluser]$ cat fpe.cc
> 	#include <stdio.h>
>
> 	    int main(void)
> 	    {
> 	      int x = (int) (4/(float)0);
> 	      printf ("x = %i\n", x);
> 	    }
>
> 	[superluser@trystero superluser]$ g++ fpe.cc
> 	fpe.cc: In function `int main()':
> 	fpe.cc:5: warning: division by zero in `4 / 0.'
> 	[superluser@trystero superluser]$ ./a.out
> 	x = 0
>
> This is gcc version 3.2 20021115 (Red Hat Linux 8.0 3.2-14). 
> Should this be normal behavior?  Is this the expected output
> of standard C++?

I've seen things like this before; it's usually the developer's 
way of obtaining a bitwise IEEE754 representation of positive 
infinity (otherwise represented as macro HUGE_VAL or INFINITY 
from math.h).  I don't know what the developer was trying to do 
here, though.

The code behaves the same way on my system (ev56) as it does on 
yours, and I'm pretty sure my compiler is solid (gcc-3.2 release 
with a few bugfix patches).  So I would expect you're getting 
the correct output.

-- 
Kelledin
"If a server crashes in a server farm and no one pings it, does 
it still cost four figures to fix?"




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

* Re: is this feature documented?
  2002-12-02 23:36 is this feature documented? Andrew A. Gill
  2002-12-03  0:08 ` Kelledin
@ 2002-12-03  7:36 ` Falk Hueffner
  1 sibling, 0 replies; 4+ messages in thread
From: Falk Hueffner @ 2002-12-03  7:36 UTC (permalink / raw)
  To: axp-list

"Andrew A. Gill" <superluser@mail.isc.rit.edu> writes:

> 	[superluser@trystero superluser]$ cat fpe.cc 
> 	#include <stdio.h>
> 
> 	    int main(void)
> 	    {
> 	      int x = (int) (4/(float)0);
> 	      printf ("x = %i\n", x);
> 	    }
> 
> 	[superluser@trystero superluser]$ g++ fpe.cc 
> 	fpe.cc: In function `int main()':
> 	fpe.cc:5: warning: division by zero in `4 / 0.'
> 	[superluser@trystero superluser]$ ./a.out 
> 	x = 0
> 
> This is gcc version 3.2 20021115 (Red Hat Linux 8.0 3.2-14).  Should
> this be normal behavior?  Is this the expected output of standard
> C++?

It is correct. 4.9: "The behavior is undefined if the truncated value
cannot be represented in the destination type." So returning 0 is
correct, as would be returning 23, crashing, or formatting the hard
disk.

It is probably not what one would expect, though; usually on Alpha,
doing calculations with magic values like NAN raises a signal. It only
doesn't happen here because the compiler does constant folding on it.

BTW, with g++ 3.3 (CVS) you get -1, and with cxx a floating point
exception.

-- 
	Falk




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

* Re: is this feature documented?
  2002-12-03  0:08 ` Kelledin
@ 2002-12-03  8:20   ` Andrew A. Gill
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew A. Gill @ 2002-12-03  8:20 UTC (permalink / raw)
  To: axp-list

On Mon, 2 Dec 2002, Kelledin antagonized the horn and now...
> 
> I've seen things like this before; it's usually the developer's 
> way of obtaining a bitwise IEEE754 representation of positive 
> infinity (otherwise represented as macro HUGE_VAL or INFINITY 
> from math.h).  I don't know what the developer was trying to do 
> here, though.

He (not she as I previously thought) was just examining a bug.  Turns 
out that there was some sort of code that produced the condition listed 
above, and he was testing this sample code.

-- 
|Andrew A. Gill                       |I posted to Silent-Tristero and|
|<superluser@mail.rit.edu>            |all I got was this stupid sig! |
|alt.tv.simpsons CBG-FAQ author       |                               |
|                          (Report all obscene mail to Le Maitre Pots)|
|Nothing here yet: <http://www.needsfoodbadly.com>    Temporary sig: --

No aspersions to the dev team.




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

end of thread, other threads:[~2002-12-03  8:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-02 23:36 is this feature documented? Andrew A. Gill
2002-12-03  0:08 ` Kelledin
2002-12-03  8:20   ` Andrew A. Gill
2002-12-03  7:36 ` Falk Hueffner

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