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 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 15:38 ` Michal Jaegermann
  1 sibling, 1 reply; 7+ messages in thread
From: Uncle George @ 2000-10-31 12:45 UTC (permalink / raw)
  To: axp-list

I get ( on rh6.2 ) on an xp1000

-339999995214436424907732413799364296704.000000
1.000000
-339999995214436424907732413799364296704.000000



Richard Polton wrote:

> 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
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list





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

* Re: strange (incorrect) arithmetic behaviour
  2000-10-31 12:45 ` Uncle George
@ 2000-10-31 13:42   ` Richard Polton
  2000-10-31 14:37     ` Stefan Schroepfer
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Polton @ 2000-10-31 13:42 UTC (permalink / raw)
  To: axp-list

Indeed. I get that on my Intel, so I am wondering where
the problem lies. Kernel, libc, gcc? Any ideas?

Uncle George wrote:
> 
> I get ( on rh6.2 ) on an xp1000
> 
> -339999995214436424907732413799364296704.000000
> 1.000000
> -339999995214436424907732413799364296704.000000
> 
> Richard Polton wrote:
> 
> > 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
> >
> > _______________________________________________
> > Axp-list mailing list
> > Axp-list@redhat.com
> > https://listman.redhat.com/mailman/listinfo/axp-list
> 
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list




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

* Re: strange (incorrect) arithmetic behaviour
  2000-10-31 13:42   ` Richard Polton
@ 2000-10-31 14:37     ` Stefan Schroepfer
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Schroepfer @ 2000-10-31 14:37 UTC (permalink / raw)
  To: axp-list

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.

Regards,
Stefan Schroepfer

Richard Polton wrote:
> 
> Indeed. I get that on my Intel, so I am wondering where
> the problem lies. Kernel, libc, gcc? Any ideas?
> 
> Uncle George wrote:
> >
> > I get ( on rh6.2 ) on an xp1000
> >
> > -339999995214436424907732413799364296704.000000
> > 1.000000
> > -339999995214436424907732413799364296704.000000
> >
> > Richard Polton wrote:
> >
> > > 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);
> > > }




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

* Re: strange (incorrect) arithmetic behaviour
  2000-10-31 10:17 strange (incorrect) arithmetic behaviour Richard Polton
  2000-10-31 12:45 ` Uncle George
@ 2000-10-31 15:38 ` Michal Jaegermann
  1 sibling, 0 replies; 7+ messages in thread
From: Michal Jaegermann @ 2000-10-31 15:38 UTC (permalink / raw)
  To: axp-list

On Tue, Oct 31, 2000 at 10:17:07AM +0000, Richard Polton wrote:
> 
> I have stock RH6.1 on my LX164 machine.

And the original kernel which came with this distribution?
Numerous problems, some of them in a floating point arithmetic,
were fixed in the meantime.

> When executing the following
> code I see SIGFPE.
......
On Alpha running 2.2.17, with or without optimizations, I see

-339999995214436424907732413799364296704.000000
1.000000
-339999995214436424907732413799364296704.000000

and 

-3.4e+38
1
-3.4e+38

if I replace "%f" with a saner here "%g" format specification.

  Michal




^ 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

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

Phil Carmody wrote:
> 
> On Tue, 31 October 2000, Stefan Schroepfer wrote:
> > Hi,
> >
> > the f format specifier is for double arguments,
> 
> 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.

Automatic promotion in C: oh well I forgot that.

If no type promotion takes place you have to cast
these values to double. Both Linux and MSVC docs
state that the f format specifier is for double
values. Some implementation might process float
as well, but that's not standard.

scr




^ 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