* division by zero exceptions ?
@ 1998-10-26 5:00 Conrad Sanderson
1998-10-26 5:00 ` Michal Jaegermann
` (2 more replies)
0 siblings, 3 replies; 20+ messages in thread
From: Conrad Sanderson @ 1998-10-26 5:00 UTC (permalink / raw)
running this C++ program on an Alpha:
void main() {
float a = 10.0; float b = 0.0;
float c = a/b;
cout << "c = " << c << endl;
}
causes "Floating exception Exit 136", while on Intel PII is says:
"c = Inf", which is the "correct" answer.
Is there any way to make the Alpha do the same thing as PII ?
I know about linking with -mieee, but that makes programs run
too slow, so that is not a solution for me.
I'm using egcs 1.1 without optimization for the above prog.
--
Conrad Sanderson - Microelectronic Signal Processing Laboratory
Griffith University, Queensland, Australia
http://spl.me.gu.edu.au [ under construction ]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-26 5:00 division by zero exceptions ? Conrad Sanderson
@ 1998-10-26 5:00 ` Michal Jaegermann
1998-10-27 5:00 ` Remco Wouts
1998-10-31 5:00 ` Shana Tackett
2 siblings, 0 replies; 20+ messages in thread
From: Michal Jaegermann @ 1998-10-26 5:00 UTC (permalink / raw)
Conrad Sanderson (conrad@hive.me.gu.edu.au) wrote:
: causes "Floating exception Exit 136", while on Intel PII is says:
: "c = Inf", which is the "correct" answer.
Read gcc documentantion, especially this part which explains
what various -mieee-... options are about and compile using one
of these (liek -mieee, for example).
: Is there any way to make the Alpha do the same thing as PII ?
Yep, but this has a performance impact as exceptions have to
be serialized.
: I know about linking with -mieee, but that makes programs run
: too slow, so that is not a solution for me.
Oh, so you heard some things. :-) If you do not care about
values on exceptions you can always install "do nothing" signal
handler for SIGFPE (see 'man signal' for details). But how about
'-mieee-with-inexact'?
Michal
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-26 5:00 division by zero exceptions ? Conrad Sanderson
1998-10-26 5:00 ` Michal Jaegermann
@ 1998-10-27 5:00 ` Remco Wouts
1998-10-28 5:00 ` Nils Faerber
1998-10-31 5:00 ` Shana Tackett
2 siblings, 1 reply; 20+ messages in thread
From: Remco Wouts @ 1998-10-27 5:00 UTC (permalink / raw)
conrad@hive.me.gu.edu.au (Conrad Sanderson) writes:
> running this C++ program on an Alpha:
>
> void main() {
> float a = 10.0; float b = 0.0;
> float c = a/b;
> cout << "c = " << c << endl;
> }
>
> causes "Floating exception Exit 136", while on Intel PII is says:
> "c = Inf", which is the "correct" answer.
First of all, this is not the correct answer. Dividing by zero is
nonsense. So actually the Alpha is right. What you mean, but what is
completely different, is that when dividing by smaller and smaller
numbers (in the limit /approaching/ zero) the resultant goes to infinity.
If you don't want to check every divisor and handle exceptions you may
want to search the documentation to see if you can trap these
exceptions. But that was already suggested by somebody else.
--
Remco Wouts remco@xray.bmc.uu.se | Dept. of Biochemistry, Uppsala University
tel/fax:+46-18-4714642/511755 | PO Box 576, S-751 23 Uppsala, Sweden.
WinErr: 00D Window closed - Do not look outside
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-27 5:00 ` Remco Wouts
@ 1998-10-28 5:00 ` Nils Faerber
0 siblings, 0 replies; 20+ messages in thread
From: Nils Faerber @ 1998-10-28 5:00 UTC (permalink / raw)
In comp.os.linux.alpha Remco Wouts <remco@xray.bmc.uu.se> wrote:
: conrad@hive.me.gu.edu.au (Conrad Sanderson) writes:
: > running this C++ program on an Alpha:
: >
: > void main() {
: > float a = 10.0; float b = 0.0;
: > float c = a/b;
: > cout << "c = " << c << endl;
: > }
: > causes "Floating exception Exit 136", while on Intel PII is says:
: > "c = Inf", which is the "correct" answer.
: First of all, this is not the correct answer. Dividing by zero is
: nonsense. So actually the Alpha is right. What you mean, but what is
Nope, sorry. For IEEE floating point, inf is the correct answer.
Mayber you should recompile your code with -mieee ?
CU
nils
--
Nils Faerber (Linux Nils) eMail: nils@unix-ag.org
Student of computer science http://www.si.unix-ag.org/~nils/
Unix user group, University of Siegen, Germany
Siegen ... the arctic rain forest!
--
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Shana Tackett
@ 1998-10-30 5:00 ` James D. Freels
1998-10-31 5:00 ` Greg Lindahl
` (2 more replies)
1998-10-31 5:00 ` Anthony W. Youngman
1998-10-31 5:00 ` Bill Metzenthen
2 siblings, 3 replies; 20+ messages in thread
From: James D. Freels @ 1998-10-30 5:00 UTC (permalink / raw)
"Shana Tackett" <sltackett@worldnet.att.net> writes:
This is a bad attitude and probably one of the main reasons why the
Alpha-Linux cannot reach it's full potential. Unfortunately, you
don't understand what large legacy code really means. When you have a
job to do, and it requires running a code that is several hundred
thousand lines of source, you don't have time to fix the bad code.
That is why the DEC Unix compilers have *AS AN OPTION* the ability to
allow the floating exceptions to occur. [see man f77 and look at
-fpe1, -fpe2, etc.] We all know it is bad code and should be fixed,
but until time and money allow it to get fixed, we must live with it
to get the job done.
So... Why don't some of you guys who know how to write compilers fix
gcc/g77 for the Alpha so that we can really use Linux instead. I
would love to now, but I can't.
> The Alpha has much better exception handling than the PII. The PII is
> setting the register to INF upon division
> by zero and continues processing. To me the Alpha is correct. You have
> asked the processor to do something
> which does not make sense and it has reported an error. Whereas the PII has
> returned an answer which has to
> interpreted as being an invalid answer. A lot of sloppy mathematical code
> will run fine on an Intel chip producing
> a result which really has no meaning. This is not so on an Alpha. It is
> better to get no answer than an answer
> which is spurious and can be wrongly interpreted as correct. Hence write
> and develop your code on the alpha this way it
> will be thoroughly tested. There are instructions in AXP which allow you to
> specifiy a function to be called upon
> a floating point exception and have the function handle the error. So it is
> possible to get the same result, although
> I would not want to.
>
> This is one of the main reasons for complications for poorly written
> mathematics code to not be easily ported from
> Intel to Alpha.
>
> Conrad Sanderson <conrad@hive.me.gu.edu.au> wrote in article
> <slrn737pv0.5bf.conrad@hive.me.gu.edu.au>...
> > running this C++ program on an Alpha:
> >
> > void main() {
> > float a = 10.0; float b = 0.0;
> > float c = a/b;
> > cout << "c = " << c << endl;
> > }
> >
> > causes "Floating exception Exit 136", while on Intel PII is says:
> > "c = Inf", which is the "correct" answer.
> >
> > Is there any way to make the Alpha do the same thing as PII ?
> > I know about linking with -mieee, but that makes programs run
> > too slow, so that is not a solution for me.
> >
> > I'm using egcs 1.1 without optimization for the above prog.
> >
> >
> > --
> > Conrad Sanderson - Microelectronic Signal Processing Laboratory
> > Griffith University, Queensland, Australia
> > http://spl.me.gu.edu.au [ under construction ]
> >
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-26 5:00 division by zero exceptions ? Conrad Sanderson
1998-10-26 5:00 ` Michal Jaegermann
1998-10-27 5:00 ` Remco Wouts
@ 1998-10-31 5:00 ` Shana Tackett
1998-10-30 5:00 ` James D. Freels
` (2 more replies)
2 siblings, 3 replies; 20+ messages in thread
From: Shana Tackett @ 1998-10-31 5:00 UTC (permalink / raw)
The Alpha has much better exception handling than the PII. The PII is
setting the register to INF upon division
by zero and continues processing. To me the Alpha is correct. You have
asked the processor to do something
which does not make sense and it has reported an error. Whereas the PII has
returned an answer which has to
interpreted as being an invalid answer. A lot of sloppy mathematical code
will run fine on an Intel chip producing
a result which really has no meaning. This is not so on an Alpha. It is
better to get no answer than an answer
which is spurious and can be wrongly interpreted as correct. Hence write
and develop your code on the alpha this way it
will be thoroughly tested. There are instructions in AXP which allow you to
specifiy a function to be called upon
a floating point exception and have the function handle the error. So it is
possible to get the same result, although
I would not want to.
This is one of the main reasons for complications for poorly written
mathematics code to not be easily ported from
Intel to Alpha.
Conrad Sanderson <conrad@hive.me.gu.edu.au> wrote in article
<slrn737pv0.5bf.conrad@hive.me.gu.edu.au>...
> running this C++ program on an Alpha:
>
> void main() {
> float a = 10.0; float b = 0.0;
> float c = a/b;
> cout << "c = " << c << endl;
> }
>
> causes "Floating exception Exit 136", while on Intel PII is says:
> "c = Inf", which is the "correct" answer.
>
> Is there any way to make the Alpha do the same thing as PII ?
> I know about linking with -mieee, but that makes programs run
> too slow, so that is not a solution for me.
>
> I'm using egcs 1.1 without optimization for the above prog.
>
>
> --
> Conrad Sanderson - Microelectronic Signal Processing Laboratory
> Griffith University, Queensland, Australia
> http://spl.me.gu.edu.au [ under construction ]
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Shana Tackett
1998-10-30 5:00 ` James D. Freels
1998-10-31 5:00 ` Anthony W. Youngman
@ 1998-10-31 5:00 ` Bill Metzenthen
2 siblings, 0 replies; 20+ messages in thread
From: Bill Metzenthen @ 1998-10-31 5:00 UTC (permalink / raw)
On 31 Oct 1998 02:59:33 GMT, Shana Tackett <sltackett@worldnet.att.net> wrote:
>The Alpha has much better exception handling than the PII. The PII is
>setting the register to INF upon division
>by zero and continues processing. To me the Alpha is correct. You have
>asked the processor to do something
>which does not make sense and it has reported an error. Whereas the PII has
>returned an answer which has to
>interpreted as being an invalid answer. A lot of sloppy mathematical code
>will run fine on an Intel chip producing
>a result which really has no meaning. This is not so on an Alpha. It is
>better to get no answer than an answer
>which is spurious and can be wrongly interpreted as correct. Hence write
>and develop your code on the alpha this way it
>will be thoroughly tested. There are instructions in AXP which allow you to
>specifiy a function to be called upon
>a floating point exception and have the function handle the error. So it is
>possible to get the same result, although
>I would not want to.
>
>This is one of the main reasons for complications for poorly written
>mathematics code to not be easily ported from
>Intel to Alpha.
>
No. This is not an issue of Intel versus Alpha. The behaviour on
Intel-based Linux machines is a result of a deliberate decision made
for later versions of libc (earlier versions caused SIGFPE). On Intel
machines, you can get the type of behaviour which you describe for the
Alpha by linking in code such as that which you will find on my web
pages. There is also a discussion of this issue and other floating
point matters there.
--
-----------------------------------------------------------------------------
Bill Metzenthen | See http://www.suburbia.net/~billm/ for information
billm@melbpc.org.au | on an 80x87 FPU emulator, using floating point
billm@suburbia.net | (particularly on Linux), and code for manipulating
Melbourne, Australia | the floating point environment on 80x86 Linux.
-----------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-30 5:00 ` James D. Freels
1998-10-31 5:00 ` Greg Lindahl
@ 1998-10-31 5:00 ` Toon Moene
1998-10-31 5:00 ` Anthony W. Youngman
1998-11-03 5:00 ` rscanon
2 siblings, 1 reply; 20+ messages in thread
From: Toon Moene @ 1998-10-31 5:00 UTC (permalink / raw)
fea@fea.rrd.ornl.gov (James D. Freels) wrote:
> So... Why don't some of you guys who know how to write compilers fix
> gcc/g77 for the Alpha so that we can really use Linux instead. I
> would love to now, but I can't.
James, I'd love to help you, but I haven't got a Linux Alpha system yet.
Because I've access to one, I might be able to get some work done if you can
supply me with a (short) example code.
However, I have to take exception to your "When you have a job to do, and it
requires running a code that is several hundred thousand lines of source, you
don't have time to fix the bad code". When code throws up a "division by
zero" exception, you just can't trust that code, even if it runs on systems
that happen to "just let it run".
--
Toon Moene (mailto:toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
g77 Support: mailto:fortran@gnu.org; egcs: mailto:egcs-bugs@cygnus.com
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-30 5:00 ` James D. Freels
@ 1998-10-31 5:00 ` Greg Lindahl
1998-10-31 5:00 ` Toon Moene
1998-11-03 5:00 ` rscanon
2 siblings, 0 replies; 20+ messages in thread
From: Greg Lindahl @ 1998-10-31 5:00 UTC (permalink / raw)
fea@fea.rrd.ornl.gov (James D. Freels) writes:
> This is a bad attitude and probably one of the main reasons why the
> Alpha-Linux cannot reach it's full potential.
Please flame over real problems, not ones for which you simply don't
know the answer.
Like most systems, Alpha/Linux allows you to play around with fp
exceptions by calling subroutines. Some compilers today let you do it
with command-line switches; that's a fairly recent development. I
don't know of any FAQ which discusses what code you need to use on the
Alpha, but it was discussed on the axp-list mailing list recently.
BTW, if you want IEEE behavior, which is what the original poster was
asking for, you need to specify -mieee when compiling. This is clearly
documented and was mentioned already in this thread.
-- g
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Shana Tackett
1998-10-30 5:00 ` James D. Freels
@ 1998-10-31 5:00 ` Anthony W. Youngman
1998-11-01 5:00 ` Greg Lindahl
1998-10-31 5:00 ` Bill Metzenthen
2 siblings, 1 reply; 20+ messages in thread
From: Anthony W. Youngman @ 1998-10-31 5:00 UTC (permalink / raw)
Apologies for copying the previous poster and replying at the top :-(
Alpha was designed by DEC and copies VMS, which also has "infinity".
What on earth is wrong with a "divide by zero" returning "infinity" as
the answer? After all it is mathematically correct.
By all means make it an option whether to return infinity or an error,
but have you ever tried maths programming with a system that only
returns an error?
Code like "x = y / tan( z)" is a damn nightmare if it is legal and
probable that z might be pi/2. I wrote code to calculate distances on a
grid, and I reckon about half the code was devoted to trapping instances
where the two points I was checking shared the same lat or long, as this
would have triggered a divide by zero. It would have been so much easier
if my compiler supported infinity, because then a following calculation
would have divided by it and returned the answer I wanted (ie d(lat)=0)
without having to put code in to trap that as a special case.
In article <01be0482$6ebd1e60$45934b0c@default>, Shana Tackett
<sltackett@worldnet.att.net> writes
>The Alpha has much better exception handling than the PII. The PII is
>setting the register to INF upon division
>by zero and continues processing. To me the Alpha is correct. You have
>asked the processor to do something
>which does not make sense and it has reported an error. Whereas the PII has
>returned an answer which has to
>interpreted as being an invalid answer. A lot of sloppy mathematical code
>will run fine on an Intel chip producing
>a result which really has no meaning. This is not so on an Alpha. It is
>better to get no answer than an answer
>which is spurious and can be wrongly interpreted as correct. Hence write
>and develop your code on the alpha this way it
>will be thoroughly tested. There are instructions in AXP which allow you to
>specifiy a function to be called upon
>a floating point exception and have the function handle the error. So it is
>possible to get the same result, although
>I would not want to.
>
>This is one of the main reasons for complications for poorly written
>mathematics code to not be easily ported from
>Intel to Alpha.
>
>Conrad Sanderson <conrad@hive.me.gu.edu.au> wrote in article
><slrn737pv0.5bf.conrad@hive.me.gu.edu.au>...
>> running this C++ program on an Alpha:
>>
>> void main() {
>> float a = 10.0; float b = 0.0;
>> float c = a/b;
>> cout << "c = " << c << endl;
>> }
>>
>> causes "Floating exception Exit 136", while on Intel PII is says:
>> "c = Inf", which is the "correct" answer.
>>
>> Is there any way to make the Alpha do the same thing as PII ?
>> I know about linking with -mieee, but that makes programs run
>> too slow, so that is not a solution for me.
>>
>> I'm using egcs 1.1 without optimization for the above prog.
>>
>>
>> --
>> Conrad Sanderson - Microelectronic Signal Processing Laboratory
>> Griffith University, Queensland, Australia
>> http://spl.me.gu.edu.au [ under construction ]
>>
--
Anthony W. Youngman - wol at thewolery dot demon dot co dot uk
Trousers with a single hole in their waistband are topologically equivalent
to a doughnut. These sugarcoated trousers have yet to catch on at fast-food
outlets! (SuperStrings by F. David Peat)
If replying by e-mail please mail wol. Anything else may get missed amongst
the spam.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Toon Moene
@ 1998-10-31 5:00 ` Anthony W. Youngman
1998-11-01 5:00 ` Stefan Davids
` (2 more replies)
0 siblings, 3 replies; 20+ messages in thread
From: Anthony W. Youngman @ 1998-10-31 5:00 UTC (permalink / raw)
In article <71f8bc$clh$3@newnews.nl.uu.net>, Toon Moene
<toon@moene.indiv.nluug.nl> writes
>fea@fea.rrd.ornl.gov (James D. Freels) wrote:
>
>> So... Why don't some of you guys who know how to write compilers fix
>> gcc/g77 for the Alpha so that we can really use Linux instead. I
>> would love to now, but I can't.
>
>James, I'd love to help you, but I haven't got a Linux Alpha system yet.
>Because I've access to one, I might be able to get some work done if you can
>supply me with a (short) example code.
>
>However, I have to take exception to your "When you have a job to do, and it
>requires running a code that is several hundred thousand lines of source, you
>don't have time to fix the bad code". When code throws up a "division by
>zero" exception, you just can't trust that code, even if it runs on systems
>that happen to "just let it run".
>
See my other post - if I'm doing math, I WANT it to return the correct
value, ie if I say "x = y / tan( pi / 2)" then I WANT x to be set to
infinity. If I don't have to trap for divide by zero, then my thousand
lines becomes five hundred, and it's a damn sight easier to debug.
Look at it as a mathematician, not an engineer. x divided by 0 IS
infinity, and I wish computers could cope with that fact, and not crash
my program.
--
Anthony W. Youngman - wol at thewolery dot demon dot co dot uk
Trousers with a single hole in their waistband are topologically equivalent
to a doughnut. These sugarcoated trousers have yet to catch on at fast-food
outlets! (SuperStrings by F. David Peat)
If replying by e-mail please mail wol. Anything else may get missed amongst
the spam.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Anthony W. Youngman
@ 1998-11-01 5:00 ` Stefan Davids
1998-11-01 5:00 ` Bill Metzenthen
1998-11-02 5:00 ` Michal Jaegermann
2 siblings, 0 replies; 20+ messages in thread
From: Stefan Davids @ 1998-11-01 5:00 UTC (permalink / raw)
Anthony W. Youngman <thewolery@nospam.demon.co.uk> wrote:
>Look at it as a mathematician, not an engineer. x divided by 0 IS
>infinity, and I wish computers could cope with that fact, and not crash
>my program.
I'm a mathematician and x/0 certainly is _NOT_ infinity - it isn't defined
and often the appropriate limit is (highly) non unique. The first few
weeks of any analysis course are usually spent hammering this into our
undergraduates.
HTH
Stefan
--
perl -we 'map{eval q(sub ).$_.q( {$_=shift; $_.=").$_.q("; s/S/s/; s/(.)/$1 /g;
@a=split; $a=join q(),@a; $b=$a; $a=~s/([A-Z])/ $1/g; $_ = join q(),reverse @a;
s/([A-Z])/$1 /g; print $a," "x(50-(length $a)*2),"$_\n"; return($b);})}((A..Z),
(q(a)..q(z)));r(e(k(c(a(H(l(r(e(P(r(e(h(t(o(n(A(t(S(u(J()))))))))))))))))))));'
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Anthony W. Youngman
1998-11-01 5:00 ` Stefan Davids
@ 1998-11-01 5:00 ` Bill Metzenthen
1998-11-01 5:00 ` Anthony W. Youngman
1998-11-02 5:00 ` Michal Jaegermann
2 siblings, 1 reply; 20+ messages in thread
From: Bill Metzenthen @ 1998-11-01 5:00 UTC (permalink / raw)
On Sat, 31 Oct 1998 21:23:20 +0000, Anthony W. Youngman
<thewolery@nospam.demon.co.uk> wrote:
>See my other post - if I'm doing math, I WANT it to return the correct
>value, ie if I say "x = y / tan( pi / 2)" then I WANT x to be set to
>infinity. If I don't have to trap for divide by zero, then my thousand
>lines becomes five hundred, and it's a damn sight easier to debug.
>
>Look at it as a mathematician, not an engineer. x divided by 0 IS
>infinity, and I wish computers could cope with that fact, and not crash
>my program.
Hang on a moment, what do you mean by infinity? In the type of
mathematics which most people would like to approximate with
floating point mathematics, there is no such thing as infinity:
x/0 is not a legal operation!
I was interested to see your example where this fictitious object can
be useful. Part of my background is in electrical engineering where
having infinity can be useful e.g. when computing the impedance of
parallel circuit branches when one of the branches is a short circuit.
I thought that this was one of the few cases where the 1/0 = infinity
behaviour was useful; your example adds one more to my list (1).
For most computations 1/0 represents a severe error which should be
dealt with as soon as it occurs.
(1) Note that in both cases, I would argue that it is really a
projective infinity which is being used. Really old Intel FPU's used
to support these but now they only support affine infinities.
--
-----------------------------------------------------------------------------
Bill Metzenthen | See http://www.suburbia.net/~billm/ for information
billm@melbpc.org.au | on an 80x87 FPU emulator, using floating point
billm@suburbia.net | (particularly on Linux), and code for manipulating
Melbourne, Australia | the floating point environment on 80x86 Linux.
-----------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Anthony W. Youngman
@ 1998-11-01 5:00 ` Greg Lindahl
0 siblings, 0 replies; 20+ messages in thread
From: Greg Lindahl @ 1998-11-01 5:00 UTC (permalink / raw)
"Anthony W. Youngman" <thewolery@nospam.demon.co.uk> writes:
> Alpha was designed by DEC and copies VMS, which also has "infinity".
> What on earth is wrong with a "divide by zero" returning "infinity" as
> the answer? After all it is mathematically correct.
If you specify -mieee (gcc) or -ieee (dec compilers), you'll get your
infinity. There's nothing wrong with IEEE being an option. Most
scientific programmers prefer a core dump; that's what is not well
documented for Linux/x86 or Linux/Alpha.
-- g
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-11-01 5:00 ` Bill Metzenthen
@ 1998-11-01 5:00 ` Anthony W. Youngman
1998-11-02 5:00 ` Stefan Davids
1998-11-02 5:00 ` Bill Metzenthen
0 siblings, 2 replies; 20+ messages in thread
From: Anthony W. Youngman @ 1998-11-01 5:00 UTC (permalink / raw)
In article <slrn73ofkl.hmt.billm@lorentz.melbpc.org.au>, Bill Metzenthen
<billm@melbpc.org.au> writes
>On Sat, 31 Oct 1998 21:23:20 +0000, Anthony W. Youngman
> <thewolery@nospam.demon.co.uk> wrote:
>
>>See my other post - if I'm doing math, I WANT it to return the correct
>>value, ie if I say "x = y / tan( pi / 2)" then I WANT x to be set to
>>infinity. If I don't have to trap for divide by zero, then my thousand
>>lines becomes five hundred, and it's a damn sight easier to debug.
>>
>>Look at it as a mathematician, not an engineer. x divided by 0 IS
>>infinity, and I wish computers could cope with that fact, and not crash
>>my program.
>
>Hang on a moment, what do you mean by infinity? In the type of
>mathematics which most people would like to approximate with
>floating point mathematics, there is no such thing as infinity:
>x/0 is not a legal operation!
>
>I was interested to see your example where this fictitious object can
>be useful. Part of my background is in electrical engineering where
>having infinity can be useful e.g. when computing the impedance of
>parallel circuit branches when one of the branches is a short circuit.
>I thought that this was one of the few cases where the 1/0 = infinity
>behaviour was useful; your example adds one more to my list (1).
>
>For most computations 1/0 represents a severe error which should be
>dealt with as soon as it occurs.
I've actually remembered exactly what I was doing.
I wanted to plot wave height at a particular point in the ocean
(iteratively - I was building an extremes map) and I had a tape of
tropical storm data.
So for each storm in turn, I took the first segment (start-pos, end-pos)
and calculated the distance from my point to the storm track, then took
the next segment, calculated the distance and kept the shortest
distance, etc etc. I then had a list of "maximum wave height from each
storm".
As you can see, it's quite an interesting problem. I think all my
coordinates were integer minutes, but I had to calculate the formula of
the line of the storm track, then calculate the formula of a line
perpendicular to the track through my point. From that I could work out
if the perpendicular intercepted the track in which case that gave me my
distance, else work out which end of the track was closest to the
perpendicular and use that to give me my distance.
As you can see, if either d(lat)=0 or d(long)=0 my code would screw up.
You state that
>For most computations 1/0 represents a severe error
but I would beg to differ. For trig and algebra, 1/0 is a linear
infinity, and (like with eg superstrings) you don't give a damn about
infinity provided at the end they all cancel out and give you your
answer. Which for trig and algebra you know they will.
I agree that when you start dividing different degrees of infinity by
each other things start getting complicated ... It's just a case of
knowing your infinities (yes there are an INFINITE NUMBER of them, I
believe :-)
--
Anthony W. Youngman - wol at thewolery dot demon dot co dot uk
Trousers with a single hole in their waistband are topologically equivalent
to a doughnut. These sugarcoated trousers have yet to catch on at fast-food
outlets! (SuperStrings by F. David Peat)
If replying by e-mail please mail wol. Anything else may get missed amongst
the spam.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-31 5:00 ` Anthony W. Youngman
1998-11-01 5:00 ` Stefan Davids
1998-11-01 5:00 ` Bill Metzenthen
@ 1998-11-02 5:00 ` Michal Jaegermann
2 siblings, 0 replies; 20+ messages in thread
From: Michal Jaegermann @ 1998-11-02 5:00 UTC (permalink / raw)
Anthony W. Youngman (thewolery@nospam.demon.co.uk) wrote:
: Look at it as a mathematician, not an engineer. x divided by 0 IS
: infinity,
As a mathematician, with Ph.D. in the area, I can tell you only the
this answer is a complete nonsense and x divided by 0 IS NOT infinity
and never was.
As an engineer you can often get away with such hacks as functions you
are dealing with are probably "well-behaved" (for a some definition of
"well-behaved") and you have some chance that what you will finally get
has some reasonable value. OTOH examples of nonsensical answers from
computer programs are abundant.
Actually quite often one should be more interested in rates of change
around singularities but, unfortunately, "engineers" tend to dimiss
the whole issue with "oh, this is an infinity".
--mj
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-11-01 5:00 ` Anthony W. Youngman
@ 1998-11-02 5:00 ` Stefan Davids
1998-11-02 5:00 ` Bill Metzenthen
1 sibling, 0 replies; 20+ messages in thread
From: Stefan Davids @ 1998-11-02 5:00 UTC (permalink / raw)
Anthony W. Youngman <thewolery@nospam.demon.co.uk> wrote:
>In article <slrn73ofkl.hmt.billm@lorentz.melbpc.org.au>, Bill Metzenthen
><billm@melbpc.org.au> writes
>>For most computations 1/0 represents a severe error
>but I would beg to differ. For trig and algebra, 1/0 is a linear
>infinity, and (like with eg superstrings) you don't give a damn about
>infinity provided at the end they all cancel out and give you your
>answer. Which for trig and algebra you know they will.
If you're planning to handle divergencies properly I suggest you need to be
_very_ clear about what sort of divergencies you're dealing with and do the
necessary analysis before programming it. I'm unaware of a C library that
allows this sort of analysis of limits.
I have no idea what you mean when you say 1/0 is a 'linear infinity'. 1/0 is
undefined - full stop. You are entitled to talk about the
_limit_ of 1/x or 1/x^2 as x tends to 0. You may be able to get a finite
answer from some combination of functions that are divergent at some point.
Generally an infinity arising in a mathematical model is a sign of
deficiency in the model.
>I agree that when you start dividing different degrees of infinity by
>each other things start getting complicated ... It's just a case of
>knowing your infinities (yes there are an INFINITE NUMBER of them, I
>believe :-)
I suggest you read a book on analysis.
regards
Stefan
--
perl -we 'map {eval q( sub ).$_.q( {$a = (shift).").$_.q("; $_ = $a; s/S/s/;
s/(A|P|H)/ $1/g;print;s/(.)/$1 /g;$_=join q(),reverse split;s/(A|P|H)/$1 /g;
print " "x(80-(length)*2), "$_\n"; return($a); } ) } ((A..Z), (q(a)..q(z)));
r(e(k(c(a(H (l(r(e(P( r(e(h(t(o(n(A( t(S(u(J( q() )))) ))))))) ))))) )))));'
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-11-01 5:00 ` Anthony W. Youngman
1998-11-02 5:00 ` Stefan Davids
@ 1998-11-02 5:00 ` Bill Metzenthen
1998-11-02 5:00 ` Conrad Sanderson
1 sibling, 1 reply; 20+ messages in thread
From: Bill Metzenthen @ 1998-11-02 5:00 UTC (permalink / raw)
On Sun, 1 Nov 1998 17:22:40 +0000, Anthony W. Youngman
<thewolery@nospam.demon.co.uk> wrote:
>You state that
>>For most computations 1/0 represents a severe error
>but I would beg to differ. For trig and algebra, 1/0 is a linear
>infinity, and (like with eg superstrings) you don't give a damn about
>infinity provided at the end they all cancel out and give you your
>answer. Which for trig and algebra you know they will.
Then we will have to agree to disagree. I will assert that 1/0 is
most likely to occur due to an oversight on the part of the
programmer. Sometimes you can get away with letting 1/0 = infinity,
either because you can support it with a mathematical system where it
is correct (e.g. projective infinity) or because you have just been
plain lucky. I believe that the IEEE didn't take up the projective
infinity option and we are stuck with affine infinites (certainly only
the very early Intel x86 FPU's supported projective infinity). You
can get away with using affine infinites as a substitute for a
projective infinity provided that you restrict the operations you
perform on them. For example, you can't use the following operations
and expect to get the correct answer:
x + y
x - y
x > y
x == y
Affine infinities can be useful but unless you are very careful
you probably won't know which one you will get when you do x/y
where (x != 0) and (y == 0).
>I agree that when you start dividing different degrees of infinity by
>each other things start getting complicated ... It's just a case of
>knowing your infinities (yes there are an INFINITE NUMBER of them, I
>believe :-)
Yes, there are an infinite number (at least a denumerable infinity of
them from Cantor's theorem) of transfinite cardinal numbers but that
is a red herring.
--
-----------------------------------------------------------------------------
Bill Metzenthen | See http://www.suburbia.net/~billm/ for information
billm@melbpc.org.au | on an 80x87 FPU emulator, using floating point
billm@suburbia.net | (particularly on Linux), and code for manipulating
Melbourne, Australia | the floating point environment on 80x86 Linux.
-----------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-11-02 5:00 ` Bill Metzenthen
@ 1998-11-02 5:00 ` Conrad Sanderson
0 siblings, 0 replies; 20+ messages in thread
From: Conrad Sanderson @ 1998-11-02 5:00 UTC (permalink / raw)
Bill Metzenthen <billm@melbpc.org.au> wrote:
>>You state that
>>>For most computations 1/0 represents a severe error
>>but I would beg to differ. For trig and algebra, 1/0 is a linear
>>infinity, and (like with eg superstrings) you don't give a damn about
>>infinity provided at the end they all cancel out and give you your
>>answer. Which for trig and algebra you know they will.
>
>Then we will have to agree to disagree. I will assert that 1/0 is
>most likely to occur due to an oversight on the part of the
>programmer. Sometimes you can get away with letting 1/0 = infinity,
I'd prefer to have my algorithm blow up with Infinity or NaN
and _handle_ that within my program. I write algorithms
which are not guaranteed to be stable, but are stable
for 99% of the data i feed them.
I could go an compile all my code with -mieee but then
I get a significant performance penalty. Whether this is
because of the quality of the code egcs generates for the
Alpha is another question. Currently it is more
viable for me to use a Pentium II/450 than an Alpha 600
because my code runs faster on the Pentium.
--
Conrad Sanderson - Microelectronic Signal Processing Laboratory
Griffith University, Queensland, Australia
http://spl.me.gu.edu.au [ under construction ]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: division by zero exceptions ?
1998-10-30 5:00 ` James D. Freels
1998-10-31 5:00 ` Greg Lindahl
1998-10-31 5:00 ` Toon Moene
@ 1998-11-03 5:00 ` rscanon
2 siblings, 0 replies; 20+ messages in thread
From: rscanon @ 1998-11-03 5:00 UTC (permalink / raw)
Here is a hack I wrote after reading some of the other
post. I agree with James though. There should be a
simple switch to have the compiler force an ignore.
The program I was having problems with compiled and ran
fine on several other platforms (IBM/AIX, SGI/IRIS,
SPARC/solaris, INTEL/Linux). However, it would stop with
a SIGFPE five seconds in on the alpha. And it wasn't a
divide by zero, it was a underflow of some sort. Ignoring
the error was fine in this case. Well, here's my hack.
Just link this c-code in with the fortran pieces.
--Shane
#include <signal.h>
void blah__();
void setup_fpe__()
{
signal(SIGFPE,blah__);
}
void blah__()
{
}
In article <v1sd879fj1h.fsf@fea.rrd.ornl.gov>,
fea@fea.rrd.ornl.gov (James D. Freels) wrote:
> "Shana Tackett" <sltackett@worldnet.att.net> writes:
>
> This is a bad attitude and probably one of the main reasons why the
> Alpha-Linux cannot reach it's full potential. Unfortunately, you
> don't understand what large legacy code really means. When you have a
> job to do, and it requires running a code that is several hundred
> thousand lines of source, you don't have time to fix the bad code.
> That is why the DEC Unix compilers have *AS AN OPTION* the ability to
> allow the floating exceptions to occur. [see man f77 and look at
> -fpe1, -fpe2, etc.] We all know it is bad code and should be fixed,
> but until time and money allow it to get fixed, we must live with it
> to get the job done.
>
> So... Why don't some of you guys who know how to write compilers fix
> gcc/g77 for the Alpha so that we can really use Linux instead. I
> would love to now, but I can't.
>
> > The Alpha has much better exception handling than the PII. The PII is
> > setting the register to INF upon division
> > by zero and continues processing. To me the Alpha is correct. You have
> > asked the processor to do something
> > which does not make sense and it has reported an error. Whereas the PII has
> > returned an answer which has to
> > interpreted as being an invalid answer. A lot of sloppy mathematical code
> > will run fine on an Intel chip producing
> > a result which really has no meaning. This is not so on an Alpha. It is
> > better to get no answer than an answer
> > which is spurious and can be wrongly interpreted as correct. Hence write
> > and develop your code on the alpha this way it
> > will be thoroughly tested. There are instructions in AXP which allow you to
> > specifiy a function to be called upon
> > a floating point exception and have the function handle the error. So it is
> > possible to get the same result, although
> > I would not want to.
> >
> > This is one of the main reasons for complications for poorly written
> > mathematics code to not be easily ported from
> > Intel to Alpha.
> >
> > Conrad Sanderson <conrad@hive.me.gu.edu.au> wrote in article
> > <slrn737pv0.5bf.conrad@hive.me.gu.edu.au>...
> > > running this C++ program on an Alpha:
> > >
> > > void main() {
> > > float a = 10.0; float b = 0.0;
> > > float c = a/b;
> > > cout << "c = " << c << endl;
> > > }
> > >
> > > causes "Floating exception Exit 136", while on Intel PII is says:
> > > "c = Inf", which is the "correct" answer.
> > >
> > > Is there any way to make the Alpha do the same thing as PII ?
> > > I know about linking with -mieee, but that makes programs run
> > > too slow, so that is not a solution for me.
> > >
> > > I'm using egcs 1.1 without optimization for the above prog.
> > >
> > >
> > > --
> > > Conrad Sanderson - Microelectronic Signal Processing Laboratory
> > > Griffith University, Queensland, Australia
> > > http://spl.me.gu.edu.au [ under construction ]
> > >
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~1998-11-03 5:00 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-10-26 5:00 division by zero exceptions ? Conrad Sanderson
1998-10-26 5:00 ` Michal Jaegermann
1998-10-27 5:00 ` Remco Wouts
1998-10-28 5:00 ` Nils Faerber
1998-10-31 5:00 ` Shana Tackett
1998-10-30 5:00 ` James D. Freels
1998-10-31 5:00 ` Greg Lindahl
1998-10-31 5:00 ` Toon Moene
1998-10-31 5:00 ` Anthony W. Youngman
1998-11-01 5:00 ` Stefan Davids
1998-11-01 5:00 ` Bill Metzenthen
1998-11-01 5:00 ` Anthony W. Youngman
1998-11-02 5:00 ` Stefan Davids
1998-11-02 5:00 ` Bill Metzenthen
1998-11-02 5:00 ` Conrad Sanderson
1998-11-02 5:00 ` Michal Jaegermann
1998-11-03 5:00 ` rscanon
1998-10-31 5:00 ` Anthony W. Youngman
1998-11-01 5:00 ` Greg Lindahl
1998-10-31 5:00 ` Bill Metzenthen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox