From: Christopher J. Grayce <cgrayce@flattop.ps.uci.edu>
Subject: SIGFPE
Date: Wed, 27 Aug 1997 07:23:45 -0700 [thread overview]
Message-ID: <199708271423.HAA22356@flattop.ps.uci.edu> (raw)
> I'm getting a SIGFPE when multiplying together
> two SMALL numbers (~1e-311 and 1e-11).
> The same multiplication on my PC Linux box returns zero
> which is perfectly acceptable. I can find nothing
> in gcc info about this behavior. Is there
> some flag (or?) I can set to correct this?
>
> Thanks.
>
> Tom Browder
>
> P.S. Using gcc from alphabits.
If those are the actual numbers you are using, I think the problem is
not an underflow on the multiply but that one of your operands is
invalid, so you are generating an invalid operation exception. That
is, 1.0e-311 is too small a double precision number to represent in 64
bits under IEEE 754 standards, so the floating point processor can't
do anything sensible with it. The smallest double precision number is
provided in <float.h> (try /usr/lib/gcc-lib/alpha-linux/2.7.2.1/
include/float.h for gcc 2.7.2.1) and is 2.2e-308 for a 64-bit double.
This being the case, we must wonder: how did you *get* 1.0e-311 as one
of your operands? I don't think you can get it by legitimate
arithmetic instructions on legitimate data. But I frequently see
exactly the results you are describing when I forget to initialize a
double variable (hence it contains garbage) and then use it in (any)
arithmetic operation.
It's also true that the same code usually generates for me no
exception on a Pentium using GCC (or often on an EB164 Alpha using DEC
C). Most of the time this just seems to be because the unitialized
variables have harmless numbers in them, for some obscure reason
reportedly related to certain deathbed mutterings of St. Thomas
Aquinas on the Nature Of The NaN. . .
But I digress. From what I can see (and I have no genuine
understanding of the issues here, so I hope more knowledgeable folk
correct this), there's another issue as well: the IEEE 754 standard
says that floating point exceptions should not in general raise a
signal but rather return certain specific values and set various
user-accessible flags to say what happened.
Now perhaps Intel/Linux/GCC gives full IEEE behaviour by default, in
which case invalid operands do not raise SIGFPE. But as I understand
it the Alpha FPU in general is not set by GCC nor DEC C to fully
conform to IEEE 754, because there is a performance hit on RISC
architectures associated with the overhead required to be able to
figure out, when a floating point exception occurs, which instruction
did the dirty deed, what type of exception it was, and what exactly
should be done about it. There is an interesting discussion of the
problem at http://www.partner.digital.com/www-swdev/pages/Home/TECH/documents/alpha_cookbook/notes.htm#ieee_float .
In particular, floating point underflows on the Alpha simply return
zero, but bogus operands raise a signal when the fastest floating
point multiply operands (mult) are generated by the compiler. You can
if you like force GCC to conform to the IEEE standard by specifying
-mieee on the compilation line. This turns mult's into multsu's and
trapb's, and bogus operands do not raise SIGFPE. I don't know just
what kind of performance hit you take in the resulting code. I'd be
interested in the answer myself.
Christopher Grayce
UCI Dept of Chemistry
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
next reply other threads:[~1997-08-27 14:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-08-27 14:23 Christopher J. Grayce [this message]
-- strict thread matches above, loose matches on Subject: below --
1997-04-10 18:31 SIGFPE Jim Paradis
1997-04-10 18:04 SIGFPE Randy Chapman
1997-04-10 19:07 ` SIGFPE Richard Henderson
1997-04-10 19:09 ` SIGFPE Richard Henderson
1997-04-10 16:09 SIGFPE Jim Paradis
1997-04-10 11:41 SIGFPE Olaf Flebbe
1997-04-09 19:05 SIGFPE Jim Paradis
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox