* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` Dag-Erling Coidan Sm�rgrav
@ 1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Jeffrey J. Potoff
1998-03-09 5:00 ` Dan A. Mercer
1998-03-06 5:00 ` John Wilson
1 sibling, 2 replies; 12+ messages in thread
From: Michael C. Grant @ 1998-03-06 5:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]
Your attitude is somewhat unattractive here, especially since you're wrong.
There is a compiler flag to disable floating-point exceptions of this type;
catching signals is a slow and unnecessarily complex solution to the
problem.
In most scientific contexts, dividing by zero is not only legal but a very
nice idiom. Working with infinity is not particularly difficult.
In fact, IEEE floating-point standards allow it. What the poster does not
know is that there is a compiler flag in DEC C++ that allows division by
zero and other floating-point exceptions to go unreported. It is on by
default because, admittedly, many people such as yourself and others _don't_
intend to divide by zero---so those of us that do should know enough to
enable it. I _disagree_ with DEC's choice here, but so be it.
Michael
Dag-Erling Coidan Sm�rgrav wrote in message ...
>Andrew Ellerton <andrewe@ned.dem.csiro.au> writes:
>> However, the C++ code will crash the entire application
>> on the DEC 4.0 version when it divides by zero. Is this
>> solvable by (for example) compiling with a certain switch?
>> Or is there any other way to stop it from crashing, or do
>> I have to resort to modifying the code?
>
>Don't do that, then.
>
>Honestly, you're complaining that your program is crashing when you're
>doing something illegal?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` mathog
@ 1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Pierre Asselin
0 siblings, 1 reply; 12+ messages in thread
From: Michael C. Grant @ 1998-03-06 5:00 UTC (permalink / raw)
Folks, it really isn't very difficult to work with division by zero and
infinities in computational code. In fact, it's a very useful idiom, and
that's precisely the reason why the IEEE floating-point standards allow it.
Don't criticize him unless you're familiar with his experience and knowledge
in these matters.
mathog@seqaxp.bio.caltech.edu wrote in message
<6dpdce$jsg@gap.cco.caltech.edu>...
>I consider think that it is a very bad idea to depend on your compiler
having a
>mode which will enable it to ignore invalid operation results (divide by
zero).
>(Except in languages with try/trap methods built into the standard.) Ok, so
you
>find the right switch, and the program no longer crashes at this illegal
>operation, but what did it do with the resulting value? It runs to
completion,
>but is the answer correct???
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` Michael C. Grant
@ 1998-03-06 5:00 ` Pierre Asselin
1998-03-08 5:00 ` Michael C. Grant
0 siblings, 1 reply; 12+ messages in thread
From: Pierre Asselin @ 1998-03-06 5:00 UTC (permalink / raw)
"Michael C. Grant" <mcgrant@mindspring.com> writes:
>Folks, it really isn't very difficult to work with division by zero and
>infinities in computational code. In fact, it's a very useful idiom, and
>that's precisely the reason why the IEEE floating-point standards allow it.
I think there's also a technical reason behind it. Something to do
with vector processors or long floating-point pipelines, and not
stalling them with an exception when an infinity or a NAN would do.
--
--Pierre Asselin, Westminster, Colorado
lpa@netcom.com
pa@verano.sba.ca.us
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` Michael C. Grant
@ 1998-03-06 5:00 ` Jeffrey J. Potoff
1998-03-09 5:00 ` Dan A. Mercer
1 sibling, 0 replies; 12+ messages in thread
From: Jeffrey J. Potoff @ 1998-03-06 5:00 UTC (permalink / raw)
Michael C. Grant wrote:
>
> Your attitude is somewhat unattractive here, especially since you're wrong.
> There is a compiler flag to disable floating-point exceptions of this type;
> catching signals is a slow and unnecessarily complex solution to the
> problem.
>
> In most scientific contexts, dividing by zero is not only legal but a very
> nice idiom. Working with infinity is not particularly difficult.
>
> In fact, IEEE floating-point standards allow it. What the poster does not
> know is that there is a compiler flag in DEC C++ that allows division by
> zero and other floating-point exceptions to go unreported. It is on by
> default because, admittedly, many people such as yourself and others _don't_
> intend to divide by zero---so those of us that do should know enough to
> enable it. I _disagree_ with DEC's choice here, but so be it.
>
Perhaps this is what you're looking for (try 'man cc') ?
-ieee
Ensure support of all portable features of the IEEE Standard for
Binary
Floating-Point Arithmetic (ANSI/IEEE Std 754-1985), including the
treatment of denormalized numbers, NaNs, and infinities and the
han-
dling of error cases. This flag also sets the _IEEE_FP C
preprocessor macro.
If your program must use IEEE signaling features that are not
portable
across different IEEE implementations, see the ieee(3) reference
page
for a discussion of how to access them under the Digital UNIX
operating
system.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Division by zero crashes on DEC should be avoidable!
@ 1998-03-06 5:00 Andrew Ellerton
1998-03-06 5:00 ` mathog
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Andrew Ellerton @ 1998-03-06 5:00 UTC (permalink / raw)
Dear All,
This is possibly a simple question:
On other UNIX platforms the application I have to port
to DEC works fine - including handling division by zero
with only a warning, presumably using not-a-number (NaN)
or INF symbols as the result. Sure, I know it should
never try to divide by zero, but it does.
However, the C++ code will crash the entire application
on the DEC 4.0 version when it divides by zero. Is this
solvable by (for example) compiling with a certain switch?
Or is there any other way to stop it from crashing, or do
I have to resort to modifying the code?
Any help most appreciated!
Regards,
Andrew
--
Andrew Ellerton andrewe @ ned.dem.csiro.au
Technical Consultant Ph 08 9389 8421 F 08 9389 1906
Currently at CSIRO Mobile 0417 931 858
Division of Exploration and Mining http://www.ned.dem.csiro.au
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 Division by zero crashes on DEC should be avoidable! Andrew Ellerton
1998-03-06 5:00 ` mathog
@ 1998-03-06 5:00 ` Dag-Erling Coidan Sm�rgrav
1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` John Wilson
1998-03-06 5:00 ` Ron Natalie
1998-03-06 5:00 ` Daniel S. Riley
3 siblings, 2 replies; 12+ messages in thread
From: Dag-Erling Coidan Sm�rgrav @ 1998-03-06 5:00 UTC (permalink / raw)
Andrew Ellerton <andrewe@ned.dem.csiro.au> writes:
> However, the C++ code will crash the entire application
> on the DEC 4.0 version when it divides by zero. Is this
> solvable by (for example) compiling with a certain switch?
> Or is there any other way to stop it from crashing, or do
> I have to resort to modifying the code?
Don't do that, then.
Honestly, you're complaining that your program is crashing when you're
doing something illegal?
The OS is *doing you a favor* by sending your program a SIGFPE, which
causes it to abort and produce a coredump, which you can then use for
debugging. If the division by zero were silently ignored, you'd never
know there had been an error, and you might actuallly rely on the
(incorrect) result the program would produce. This might not be of any
significance - it might simply mean an incorrect display in, say, a
game - or it could cost lives.
And if you are really, really 100% certain that dividing by zero is
the correct behaviour for your program (in which case IMHO you need to
*seriously* rethink your design) then *catch the signal*. signal(2) is
there for a reason. Install a SIGFPE handler which notifies the user
that an illegal operation was attempted.
For more information, RTFM.
--
"I have a closed mind. It helps keeping the rain out." (Michael Press on a.s.r)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 Division by zero crashes on DEC should be avoidable! Andrew Ellerton
` (2 preceding siblings ...)
1998-03-06 5:00 ` Ron Natalie
@ 1998-03-06 5:00 ` Daniel S. Riley
3 siblings, 0 replies; 12+ messages in thread
From: Daniel S. Riley @ 1998-03-06 5:00 UTC (permalink / raw)
To: Andrew Ellerton
[mailed and posted, followup-to set]
Andrew Ellerton <andrewe@ned.dem.csiro.au> writes:
> However, the C++ code will crash the entire application
> on the DEC 4.0 version when it divides by zero. Is this
> solvable by (for example) compiling with a certain switch?
'cxx -ieee', if you have a new enough version of cxx. If you are
using g++, you will probably have to modify the code--I do not know
of any way to get full IEEE semantics with g++ on the Alpha.
--
Dan Riley dsr@mail.lns.cornell.edu
Wilson Lab, Cornell University <URL:http://www.lns.cornell.edu/~dsr/>
"History teaches us that days like this are best spent in bed"
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 Division by zero crashes on DEC should be avoidable! Andrew Ellerton
1998-03-06 5:00 ` mathog
1998-03-06 5:00 ` Dag-Erling Coidan Sm�rgrav
@ 1998-03-06 5:00 ` Ron Natalie
1998-03-06 5:00 ` Daniel S. Riley
3 siblings, 0 replies; 12+ messages in thread
From: Ron Natalie @ 1998-03-06 5:00 UTC (permalink / raw)
Andrew Ellerton wrote:
> On other UNIX platforms the application I have to port
> to DEC works fine - including handling division by zero
> with only a warning, presumably using not-a-number (NaN)
> or INF symbols as the result. Sure, I know it should
> never try to divide by zero, but it does.
On SOME other UNIX platforms. Actually, machines that do not
FPE on divide by zero's are the exception in my experience,
you're doing an invalid operation, don't you want to know about
it?
You'll also find the DEC unique in that it will FPE even on
doubles from memory that have invalid format (most machines
don't FPE until you do an opreation with them). Make sure
things are INITIALIZED.
> However, the C++ code will crash the entire application
> on the DEC 4.0 version when it divides by zero. Is this
> solvable by (for example) compiling with a certain switch?
> Or is there any other way to stop it from crashing, or do
> I have to resort to modifying the code?
There might be a compiler option, I don't know.
You could also try catching/ignoring SIGFPE, but that's
frought with peril.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` Dag-Erling Coidan Sm�rgrav
1998-03-06 5:00 ` Michael C. Grant
@ 1998-03-06 5:00 ` John Wilson
1 sibling, 0 replies; 12+ messages in thread
From: John Wilson @ 1998-03-06 5:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 978 bytes --]
In article <xzpd8g03t8k.fsf@grjottunagard.ifi.uio.no>,
Dag-Erling Coidan Sm�rgrav <dag-erli@ifi.uio.no> wrote:
>Honestly, you're complaining that your program is crashing when you're
>doing something illegal?
>
>The OS is *doing you a favor* by sending your program a SIGFPE, which
>causes it to abort and produce a coredump, which you can then use for
>debugging. If the division by zero were silently ignored, you'd never
>know there had been an error, and you might actuallly rely on the
>(incorrect) result the program would produce.
Well, this depends on how you look at it. IEEE math goes to a whole lot of
trouble to handle this kind of thing in a semi-useful way (the error isn't
silently ignored, it gets propogated precisely so that you *don't* end up
with random results the way you would on older proprietary FP systems),
it seems silly to let the C RTS defeat that since otherwise IEEE math is no
better than the chaos that preceeded it.
John Wilson
D Bit
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 Division by zero crashes on DEC should be avoidable! Andrew Ellerton
@ 1998-03-06 5:00 ` mathog
1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Dag-Erling Coidan Sm�rgrav
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: mathog @ 1998-03-06 5:00 UTC (permalink / raw)
In article <34FF7719.41C6@ned.dem.csiro.au>, Andrew Ellerton <andrewe@ned.dem.csiro.au> writes:
>Dear All,
>
>This is possibly a simple question:
>
> On other UNIX platforms the application I have to port
> to DEC works fine - including handling division by zero
> with only a warning, presumably using not-a-number (NaN)
> or INF symbols as the result. Sure, I know it should
> never try to divide by zero, but it does.
>
> However, the C++ code will crash the entire application
> on the DEC 4.0 version when it divides by zero. Is this
> solvable by (for example) compiling with a certain switch?
>
For the OpenVMS version of DEC C++ there is a /IEEE_MODE, the HELP for it
says:
CXX
/IEEE_MODE=option
Selects the IEEE floating-point mode to be used if /FLOAT=IEEE_FLOAT
is specified. You can select from the following options:
FAST During program execution, only finite values (no
infinities, NaNs, or denorms) are created.
Exceptional conditions, such as floating-point
overflow and divide-by-zero, are fatal. This is
the default option.
UNDERFLOW_TO_ZERO Generate infinities and NaNs. Flush denormalized
results and underflow to zero without exceptions.
DENORM_RESULTS Same as UNDERFLOW_TO_ZERO, except that denorms are
generated.
INEXACT Same as DENORM_RESULTS, except that inexact values
are trapped. This is the slowest mode.
The default is /IEEE_MODE=FAST.
So, try something like -IEEE_MODE=UNDERFLOW_TO_ZERO (syntax is almost certainly
different than that given here.)
> Or is there any other way to stop it from crashing, or do
> I have to resort to modifying the code?
I consider think that it is a very bad idea to depend on your compiler having a
mode which will enable it to ignore invalid operation results (divide by zero).
(Except in languages with try/trap methods built into the standard.) Ok, so you
find the right switch, and the program no longer crashes at this illegal
operation, but what did it do with the resulting value? It runs to completion,
but is the answer correct???
Regards,
David Mathog
mathog@seqaxp.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech
**************************************************************************
* Affordable VMS? See: http://seqaxp.bio.caltech.edu/www/pcvms.html *
**************************************************************************
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` Pierre Asselin
@ 1998-03-08 5:00 ` Michael C. Grant
0 siblings, 0 replies; 12+ messages in thread
From: Michael C. Grant @ 1998-03-08 5:00 UTC (permalink / raw)
You're quite correct. For a number of reasons, including pipelining issues,
floating-point exceptions can significantly decrease the performance of a
piece of computational code. And I don't want the processor to have to empty
its floating-point pipeline just to tell me something that I already know.
Interestingly, many pipelining issues reared their ugly head _after_ the
IEEE floating-point standard was already established. In fact, if I remember
correctly, certain Alpha processors purposefully violate certain more
esoteric parts of the standard, in order to preserve the pipeline in
exceptional circumstances.
So unnecessary floating-point exceptions can _seriously_ compromise the
performance of floating-point code. But so can writing a bunch of extra code
to manually detect division by zero.
No matter what, it is always important to fully understand the consequences
of division by zero, etc. when writing numerical code. If your code
considers a division by zero to be an exceptional occurrence, then I say
that it's _your_ responsibility to throw an exception---and it's _your_
responsibility to document your code so that its users avoid that pitfall.
Don't let the compiler do your work for you, because invariably it doesn't
catch everything.
Michael
Pierre Asselin wrote in message ...
>"Michael C. Grant" <mcgrant@mindspring.com> writes:
>
>>Folks, it really isn't very difficult to work with division by zero and
>>infinities in computational code. In fact, it's a very useful idiom, and
>>that's precisely the reason why the IEEE floating-point standards allow
it.
>
>I think there's also a technical reason behind it. Something to do
>with vector processors or long floating-point pipelines, and not
>stalling them with an exception when an infinity or a NAN would do.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Division by zero crashes on DEC should be avoidable!
1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Jeffrey J. Potoff
@ 1998-03-09 5:00 ` Dan A. Mercer
1 sibling, 0 replies; 12+ messages in thread
From: Dan A. Mercer @ 1998-03-09 5:00 UTC (permalink / raw)
Michael C. Grant (mcgrant@mindspring.com) wrote:
: Your attitude is somewhat unattractive here, especially since you're wrong.
: There is a compiler flag to disable floating-point exceptions of this type;
: catching signals is a slow and unnecessarily complex solution to the
: problem.
: In most scientific contexts, dividing by zero is not only legal but a very
: nice idiom. Working with infinity is not particularly difficult.
Mathematically speaking, the solution of 0/0 is not infinity but lies
in the range of numbers between 0 and infinity.
--
Dan Mercer
Reply To: damercer@mmm.com
Opinions expressed herein are my own and may not represent those of my employer.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~1998-03-09 5:00 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-03-06 5:00 Division by zero crashes on DEC should be avoidable! Andrew Ellerton
1998-03-06 5:00 ` mathog
1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Pierre Asselin
1998-03-08 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Dag-Erling Coidan Sm�rgrav
1998-03-06 5:00 ` Michael C. Grant
1998-03-06 5:00 ` Jeffrey J. Potoff
1998-03-09 5:00 ` Dan A. Mercer
1998-03-06 5:00 ` John Wilson
1998-03-06 5:00 ` Ron Natalie
1998-03-06 5:00 ` Daniel S. Riley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox