Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* strange (incorrect) arithmetic behaviour
@ 2000-10-31 10:17 Richard Polton
  2000-10-31 12:45 ` Uncle George
  2000-10-31 15:38 ` Michal Jaegermann
  0 siblings, 2 replies; 7+ messages in thread
From: Richard Polton @ 2000-10-31 10:17 UTC (permalink / raw)
  To: axp-list

Hi,

I have stock RH6.1 on my LX164 machine. When executing the following
code I see SIGFPE.

#include <stdio.h>
#include <math.h>

main()
{
  float a = -3.4e38;
  float b = 1.0;
  float c = a*b;
  printf( "%f\n%f\n%f\n", a, b, c);
}

In gdb I can see that c contains 2.4e-314 which is not the
expected result ;). To compile I use egcs-2.91.66 as supplied with
RH6.1 with no additional command line options.
What am I missing or doing incorrectly?

Thanks,

Richard




^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: strange (incorrect) arithmetic behaviour
@ 2000-10-31 22:36 Phil Carmody
  2000-11-02 13:35 ` Stefan Schroepfer
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Carmody @ 2000-10-31 22:36 UTC (permalink / raw)
  To: axp-list

On Tue, 31 October 2000, Stefan Schroepfer wrote:
> Hi,
> 
> the f format specifier is for double arguments,
> so try
> 
>   printf( "%f\n%f\n%f\n", (double)a, (double)b, (double)c);
> 
> instead.

They were double arguments already, as this is C. In C++ there is no such automatic promotion, and when you want to pass a float, you simply pass a float.

Phil

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] 7+ messages in thread

end of thread, other threads:[~2000-11-02 13:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-10-31 10:17 strange (incorrect) arithmetic behaviour Richard Polton
2000-10-31 12:45 ` Uncle George
2000-10-31 13:42   ` Richard Polton
2000-10-31 14:37     ` Stefan Schroepfer
2000-10-31 15:38 ` Michal Jaegermann
  -- strict thread matches above, loose matches on Subject: below --
2000-10-31 22:36 Phil Carmody
2000-11-02 13:35 ` Stefan Schroepfer

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