Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Re: Floating point on alpha
@ 2002-07-02 13:10 Peter Petrakis
  2002-07-02 19:37 ` Floating point on alpha - SOLUTION 1 Linus Gasser
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Petrakis @ 2002-07-02 13:10 UTC (permalink / raw)
  To: axp-list

Well,
Adding '-mieee' to your compile flags will solve the FPE however you
may be better off to cast the comparison to an (int). Testing for
the positive case doesn't require 64 bits of precision ;-P .

Peter



> ineiti@gmx.net said:
> > I have a general question for alphas: from time to time when I try to
> > compile  a program for my alpha (PC164), I run into problems with
> > doubles. For example
> 
> > {
> > 	double a;
> 
> > 	if ( a ){
> > 		printf( "love\n" );
> > 	} else {
> > 		printf( "peace\n" );
> > 	} }
> 
> Ah, well.  If your whole point is avoid a crash, you can always try:
> 
> #include <signal.h>
> static void myHandler(int i)
> {
>   signal(i, myHandler);
> }
> 
> And add this near the start of the main program:
> 
>   signal(SIGFPE, myHandler);
> 
> But then again, it might be better to actually fix the code...
> 
> Cheers,
> 					Christian
> 
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list



--
www.alphadriven.org




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

* Re: Floating point on alpha - SOLUTION 1
  2002-07-02 13:10 Floating point on alpha Peter Petrakis
@ 2002-07-02 19:37 ` Linus Gasser
  2002-07-02 20:45   ` Joseph Ashwood
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Gasser @ 2002-07-02 19:37 UTC (permalink / raw)
  To: axp-list

Yes,
that did it! OK, it's not nice. I'll try the other alternatives, too. What's 
really not nice, it's a division with a non-initialised double. Not a test... 
F*CK with -miee I can divide by 0 w/o trouble! What the heck is this? I can 
have

double a = 0, b = 1, c = 2;
b = c / a;

Someone wake me up! What is going on here?

ineiti

On Tuesday 02 July 2002 15:10, you wrote:
> Well,
> Adding '-mieee' to your compile flags will solve the FPE however you
> may be better off to cast the comparison to an (int). Testing for
> the positive case doesn't require 64 bits of precision ;-P .
>
> Peter
> > ineiti@gmx.net said:
> > > I have a general question for alphas: from time to time when I try to
> > > compile  a program for my alpha (PC164), I run into problems with
> > > doubles. For example
> > >
> > > {
> > > 	double a;
> > >
> > > 	if ( a ){
> > > 		printf( "love\n" );
> > > 	} else {
> > > 		printf( "peace\n" );
> > > 	} }
> >
> > Ah, well.  If your whole point is avoid a crash, you can always try:
> >
> > #include <signal.h>
> > static void myHandler(int i)
> > {
> >   signal(i, myHandler);
> > }
> >
> > And add this near the start of the main program:
> >
> >   signal(SIGFPE, myHandler);
> >
> > But then again, it might be better to actually fix the code...
> >
> > Cheers,
> > 					Christian
> >
> > _______________________________________________
> > Axp-list mailing list
> > Axp-list@redhat.com
> > https://listman.redhat.com/mailman/listinfo/axp-list




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

* Re: Floating point on alpha - SOLUTION 1
  2002-07-02 19:37 ` Floating point on alpha - SOLUTION 1 Linus Gasser
@ 2002-07-02 20:45   ` Joseph Ashwood
  2002-07-02 21:18     ` Chris Eleveld
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Ashwood @ 2002-07-02 20:45 UTC (permalink / raw)
  To: axp-list

----- Original Message -----
From: "Linus Gasser" <ineiti@gmx.net>

> F*CK with -miee I can divide by 0 w/o trouble! What the heck is this? I
can
> have
>
> double a = 0, b = 1, c = 2;
> b = c / a;
>
> Someone wake me up! What is going on here?

There are a few possible explanations, sorry I don't know which one it is
don't have Alpha docs in front of me right now. Depending on the chip
itself, it may actually have a 0 for floating point numbers, 0 will actually
be 2^-500 or something, which will introduce very small errors, but usually
nothing that is critical. This takes care of division by 0 very cleanly, by
eliminating the possibility. The second possibility is that division by 0
results in a special code output, IIRC Alpha does NOT use this one, it is
exclusively the realm of PowerPC. Third possibility, division by 0 creates
an output of infinite, if you print this to the screen it is generally
printed as "#INF" or something similar. The fourth possibility is
that -mieee switched off the floating point signaling completely so your
division by 0 error goes undetected, and b receives garbage. It will take
some experimentation and documentation to determine which of these (possibly
case 1 and 3 in some cases) is the actual result.

If you are writing something the needs to be portable, you will need to
address all of these cases, since different systems behave slightly
differently.
                            Joe




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

* RE: Floating point on alpha - SOLUTION 1
  2002-07-02 20:45   ` Joseph Ashwood
@ 2002-07-02 21:18     ` Chris Eleveld
  2002-07-02 22:32       ` Joseph Ashwood
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Eleveld @ 2002-07-02 21:18 UTC (permalink / raw)
  To: axp-list

Shouldn't this generate NaN(Not A Number) verifiable by if (b !=
b)printf("NaN!\n");

-----Original Message-----
From: axp-list-admin@redhat.com [mailto:axp-list-admin@redhat.com] On
Behalf Of Joseph Ashwood
Sent: Tuesday, July 02, 2002 3:46 PM
To: axp-list@redhat.com
Subject: Re: Floating point on alpha - SOLUTION 1


----- Original Message -----
From: "Linus Gasser" <ineiti@gmx.net>

> F*CK with -miee I can divide by 0 w/o trouble! What the heck is this?
I
can
> have
>
> double a = 0, b = 1, c = 2;
> b = c / a;
>
> Someone wake me up! What is going on here?

There are a few possible explanations, sorry I don't know which one it
is
don't have Alpha docs in front of me right now. Depending on the chip
itself, it may actually have a 0 for floating point numbers, 0 will
actually
be 2^-500 or something, which will introduce very small errors, but
usually
nothing that is critical. This takes care of division by 0 very cleanly,
by
eliminating the possibility. The second possibility is that division by
0
results in a special code output, IIRC Alpha does NOT use this one, it
is
exclusively the realm of PowerPC. Third possibility, division by 0
creates
an output of infinite, if you print this to the screen it is generally
printed as "#INF" or something similar. The fourth possibility is
that -mieee switched off the floating point signaling completely so your
division by 0 error goes undetected, and b receives garbage. It will
take
some experimentation and documentation to determine which of these
(possibly
case 1 and 3 in some cases) is the actual result.

If you are writing something the needs to be portable, you will need to
address all of these cases, since different systems behave slightly
differently.
                            Joe



_______________________________________________
Axp-list mailing list
Axp-list@redhat.com
https://listman.redhat.com/mailman/listinfo/axp-list




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

* Re: Floating point on alpha - SOLUTION 1
  2002-07-02 21:18     ` Chris Eleveld
@ 2002-07-02 22:32       ` Joseph Ashwood
  0 siblings, 0 replies; 5+ messages in thread
From: Joseph Ashwood @ 2002-07-02 22:32 UTC (permalink / raw)
  To: axp-list

----- Original Message -----
From: "Chris Eleveld" <Chris_Eleveld@sector7.com>

> Shouldn't this generate NaN(Not A Number) verifiable by if (b !=
> b)printf("NaN!\n");

Oops, forgot that possibility (which is subtly, but importantly different
from my #2). Thanx
for the correction.
                    Joe





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

end of thread, other threads:[~2002-07-02 22:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-02 13:10 Floating point on alpha Peter Petrakis
2002-07-02 19:37 ` Floating point on alpha - SOLUTION 1 Linus Gasser
2002-07-02 20:45   ` Joseph Ashwood
2002-07-02 21:18     ` Chris Eleveld
2002-07-02 22:32       ` Joseph Ashwood

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