My first thought was that you should be able to use signals to catch these types of floating point exceptions...
$SIG{FPE}=sub{...};
...but it turns out that perl is too
smart and catches these types of errors before passing them on to the hardware. Does anyone know if there is a compiler flag for perl which would disable these checks? Just for the fun of it I compiled up a version of perl which commented out the divide by zero check (in
pp.c)...
/*if (right == 0.0)
DIE(aTHX_ "Illegal division by zero");*/
...make, compile, run...
$ ./perl -e '$a=1.23/0.00;print "\$a=$a\n"'
$a=inf
...looks like we're going down the right track...
if (right == 0.0)
PUSHs(&PL_sv_undef);/*DIE(aTHX_ "Illegal division by zero");*/
else
PUSHn( left / right );
...make, compile, rerun...
$ ./perl -e 'print "UNDEFINED\n" unless (defined(1.23/0.00))'
UNDEFINED
Of course you'd probably want to take care of the integer division case also.
-- All code is 100% tested and functional unless otherwise noted.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.