* Floating point on alpha
@ 2002-07-02 12:10 Linus Gasser
2002-07-02 12:33 ` Doug Trainor
2002-07-02 13:01 ` Christian Iseli
0 siblings, 2 replies; 12+ messages in thread
From: Linus Gasser @ 2002-07-02 12:10 UTC (permalink / raw)
To: axp-list
Hi all,
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" );
}
}
seems to run w/o problems on an i386 and produces "peace" as output. Now, on
an alpha (can't test it right now, but try it out and tell me), it segfaults,
cause 'a' is not defined. Seems logical to me. But as it runs on i386, lots
of programs have this kind of logic (gnome-print had it, breakout2 had it,
scribus had it, noteedit has it (note the had/has and try to figure out which
program I'd like to run on my alpha ;-) ).
Now my question: is it possible to remove this behaviour with a good
compiler-switch? Because going over these programs, searching for
non-initialised doubles gets on my nerves. OK, I should, as it is really bad
programming, and I could contribute like this (and did sometimes). But
still... Any hints?
Ineiti
PS: if this 'magic' compiler switch doesn't exist, I have a question about gdb
with libraries and how to use the '-g' switch in this case. Just to find
those #@$%-variables...
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Floating point on alpha
2002-07-02 12:10 Linus Gasser
@ 2002-07-02 12:33 ` Doug Trainor
2002-07-02 14:03 ` Linus Gasser
2002-07-02 13:01 ` Christian Iseli
1 sibling, 1 reply; 12+ messages in thread
From: Doug Trainor @ 2002-07-02 12:33 UTC (permalink / raw)
To: axp-list
Just because the other kids do it doesn't mean you have to.
You could run Splint... [or something like the old UNIX lint(1)]
http://lclint.cs.virginia.edu/
http://sourceforge.net/projects/lclint/
etc
Linus Gasser wrote:
> Hi all,
> 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" );
> }
> }
>
> seems to run w/o problems on an i386 and produces "peace" as output. Now, on
> an alpha (can't test it right now, but try it out and tell me), it segfaults,
> cause 'a' is not defined. Seems logical to me. But as it runs on i386, lots
> of programs have this kind of logic (gnome-print had it, breakout2 had it,
> scribus had it, noteedit has it (note the had/has and try to figure out which
> program I'd like to run on my alpha ;-) ).
> Now my question: is it possible to remove this behaviour with a good
> compiler-switch? Because going over these programs, searching for
> non-initialised doubles gets on my nerves. OK, I should, as it is really bad
> programming, and I could contribute like this (and did sometimes). But
> still... Any hints?
>
> Ineiti
>
> PS: if this 'magic' compiler switch doesn't exist, I have a question about gdb
> with libraries and how to use the '-g' switch in this case. Just to find
> those #@$%-variables...
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Floating point on alpha
2002-07-02 12:10 Linus Gasser
2002-07-02 12:33 ` Doug Trainor
@ 2002-07-02 13:01 ` Christian Iseli
1 sibling, 0 replies; 12+ messages in thread
From: Christian Iseli @ 2002-07-02 13:01 UTC (permalink / raw)
To: axp-list
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* 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; 12+ 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] 12+ messages in thread
* Re: Floating point on alpha
2002-07-02 12:33 ` Doug Trainor
@ 2002-07-02 14:03 ` Linus Gasser
2002-07-02 14:22 ` Joerg Bruehe
0 siblings, 1 reply; 12+ messages in thread
From: Linus Gasser @ 2002-07-02 14:03 UTC (permalink / raw)
To: axp-list
Hi,
just had a look at the documentation, and found the following:
>>
Like many static checkers, Splint detects instances where the value of a
location is used before it is defined. This analysis is done at the
procedural level. If there is a path through the procedure that uses a local
variable before it is defined, a use before definition error is reported.
The usedef flag controls use before definition checking.
<<
That means that if I call a function with a non-initialised double it won't be
detected. But it should.
Hmm, I gotta try that gdb once again. Trouble is: if I run it on noteedit, it
crashes in a library (libnoteedit.so.1), and I don't get gdb to read the
symbol-table. OK, at least I get the function-name where it crashes, but not
the line. And always putting cout << x << endl; in the code to see where it
crashes is not my idea of debugging. Any better ideas?
Ineiti
On Tuesday 02 July 2002 14:33, Doug Trainor wrote:
> Just because the other kids do it doesn't mean you have to.
>
> You could run Splint... [or something like the old UNIX lint(1)]
>
> http://lclint.cs.virginia.edu/
> http://sourceforge.net/projects/lclint/
> etc
>
> Linus Gasser wrote:
> > Hi all,
> > 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" );
> > }
> > }
> >
> > seems to run w/o problems on an i386 and produces "peace" as output. Now,
> > on an alpha (can't test it right now, but try it out and tell me), it
> > segfaults, cause 'a' is not defined. Seems logical to me. But as it runs
> > on i386, lots of programs have this kind of logic (gnome-print had it,
> > breakout2 had it, scribus had it, noteedit has it (note the had/has and
> > try to figure out which program I'd like to run on my alpha ;-) ).
> > Now my question: is it possible to remove this behaviour with a good
> > compiler-switch? Because going over these programs, searching for
> > non-initialised doubles gets on my nerves. OK, I should, as it is really
> > bad programming, and I could contribute like this (and did sometimes).
> > But still... Any hints?
> >
> > Ineiti
> >
> > PS: if this 'magic' compiler switch doesn't exist, I have a question
> > about gdb with libraries and how to use the '-g' switch in this case.
> > Just to find those #@$%-variables...
> >
> > _______________________________________________
> > 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] 12+ messages in thread
* Re: Floating point on alpha
2002-07-02 14:03 ` Linus Gasser
@ 2002-07-02 14:22 ` Joerg Bruehe
0 siblings, 0 replies; 12+ messages in thread
From: Joerg Bruehe @ 2002-07-02 14:22 UTC (permalink / raw)
To: axp-list
Hi!
Linus Gasser wrote:
>
> Hi,
> just had a look at the documentation, and found the following:
>
> >>
> Like many static checkers, Splint detects instances where the value of a
> location is used before it is defined. This analysis is done at the
> procedural level. If there is a path through the procedure that uses a local
> variable before it is defined, a use before definition error is reported.
> The usedef flag controls use before definition checking.
> <<
>
> That means that if I call a function with a non-initialised double it won't be
> detected. But it should.
IMO, you mis-interpret the docu:
Sure, "splint" will not detect that the current function was called
with a non-initialised double,
but it will (hopefully) detect that the current function _is_calling_
some other with a non-initialised double, and that is the point of
error which needs to be corrected.
> Hmm, I gotta try that gdb once again. Trouble is: if I run it on noteedit, it
> crashes in a library (libnoteedit.so.1), and I don't get gdb to read the
> symbol-table. OK, at least I get the function-name where it crashes, but not
> the line. And always putting cout << x << endl; in the code to see where it
> crashes is not my idea of debugging. Any better ideas?
Check the point of calling, that is where the garbage parameter
is given.
HTH,
Joerg Bruehe
P.S.: And please, no top-post with full-quote in the future.
--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
(speaking only for himself)
mailto: joerg@sql.de
^ permalink raw reply [flat|nested] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ messages in thread
* RE: Floating point on alpha
@ 2002-07-08 22:54 Donsbach, Jeff
2002-07-09 2:42 ` Alvin Starr
0 siblings, 1 reply; 12+ messages in thread
From: Donsbach, Jeff @ 2002-07-08 22:54 UTC (permalink / raw)
To: axp-list
Purify would flag this usage of "a" as a "UMR" or uninitialized memory read. I.e. it is a lurking bug. Stack variables are not required to be initialized to zero as the code seems to assume.
> -----Original Message-----
> From: Linus Gasser [mailto:ineiti@gmx.net]
> Sent: Tuesday, July 02, 2002 8:11 AM
> To: axp-list@redhat.com
> Subject: Floating point on alpha
>
>
> Hi all,
> 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" );
> }
> }
>
> seems to run w/o problems on an i386 and produces "peace" as
> output. Now, on
> an alpha (can't test it right now, but try it out and tell
> me), it segfaults,
> cause 'a' is not defined. Seems logical to me. But as it runs
> on i386, lots
> of programs have this kind of logic (gnome-print had it,
> breakout2 had it,
> scribus had it, noteedit has it (note the had/has and try to
> figure out which
> program I'd like to run on my alpha ;-) ).
> Now my question: is it possible to remove this behaviour with a good
> compiler-switch? Because going over these programs, searching for
> non-initialised doubles gets on my nerves. OK, I should, as
> it is really bad
> programming, and I could contribute like this (and did
> sometimes). But
> still... Any hints?
>
> Ineiti
>
> PS: if this 'magic' compiler switch doesn't exist, I have a
> question about gdb
> with libraries and how to use the '-g' switch in this case.
> Just to find
> those #@$%-variables...
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Floating point on alpha
2002-07-08 22:54 Floating point on alpha Donsbach, Jeff
@ 2002-07-09 2:42 ` Alvin Starr
0 siblings, 0 replies; 12+ messages in thread
From: Alvin Starr @ 2002-07-09 2:42 UTC (permalink / raw)
To: axp-list
Donsbach, Jeff wrote:
> Purify would flag this usage of "a" as a "UMR" or uninitialized memory read. I.e. it is a lurking bug. Stack variables are not required to be initialized to zero as the code seems to assume.
>
>
>
>>-----Original Message-----
>>From: Linus Gasser [mailto:ineiti@gmx.net]
>>Sent: Tuesday, July 02, 2002 8:11 AM
>>To: axp-list@redhat.com
>>Subject: Floating point on alpha
>>
>>
>>Hi all,
>>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 ){
It has always been my impression that testing a float for 0 is in
general not a good idea. If you set it to 0 you will usualy get the
response you expect but there are a number of issues around floating
point numbers and the formats they are kept in. Like +0 and -0 not being
quite the same as 0. The other thing is that you can get a number very
close to 0 but is not quite 0. There is a certain amount of ambiguity
about floting point numbers and it just does not seem good form to use
them as boolean values. There are more floating point formats out there
than you can shake a stick at and you need to be carefull when using them.
>> printf( "love\n" );
>> } else {
>> printf( "peace\n" );
>> }
>>}
>>
>>seems to run w/o problems on an i386 and produces "peace" as
>>output. Now, on
>>an alpha (can't test it right now, but try it out and tell
>>me), it segfaults,
>>cause 'a' is not defined. Seems logical to me. But as it runs
>>on i386, lots
>>of programs have this kind of logic (gnome-print had it,
>>breakout2 had it,
>>scribus had it, noteedit has it (note the had/has and try to
>>figure out which
>>program I'd like to run on my alpha ;-) ).
>> Now my question: is it possible to remove this behaviour with a good
>>compiler-switch? Because going over these programs, searching for
>>non-initialised doubles gets on my nerves. OK, I should, as
>>it is really bad
>>programming, and I could contribute like this (and did
>>sometimes). But
>>still... Any hints?
>>
>>Ineiti
>>
>>PS: if this 'magic' compiler switch doesn't exist, I have a
>>question about gdb
>>with libraries and how to use the '-g' switch in this case.
>>Just to find
>>those #@$%-variables...
--
Alvin Starr || voice: (416)585-9971
Interlink Connectivity || fax: (416)585-9974
alvin@iplink.net ||
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2002-07-09 2:42 UTC | newest]
Thread overview: 12+ 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
-- strict thread matches above, loose matches on Subject: below --
2002-07-08 22:54 Floating point on alpha Donsbach, Jeff
2002-07-09 2:42 ` Alvin Starr
2002-07-02 12:10 Linus Gasser
2002-07-02 12:33 ` Doug Trainor
2002-07-02 14:03 ` Linus Gasser
2002-07-02 14:22 ` Joerg Bruehe
2002-07-02 13:01 ` Christian Iseli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox