Reverend monks,
Please enlighten me.... I'd like to detect overflow during integer
operations. Using the integer pragma guarantees that Perl
does not converts integers to reals, but it doesn't detect
overflow...
I'm trying to write a Perl module to do arithmetic on arbitrary precision
integers. Obviously, these new operation will pay an overload on built-in
operators for these cases in which the latter can be used. So I'd like to use
standard built-in whenever possible. I tried to do something like
sub add {
use integers;
my $result = eval {$_[0] + $_[1]};
return $result if (defined $result);
goto &myadd;
}
where myadd is the subroutine handling the case where one
at least is a "big" integer.. Well, it didn't work :( Even with the
inter pragma, overflow errors aren't detected... Any idea?
TheHobbit</strong/
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.