# New Ticket Created by (Peter J. Acklam)
# Please include the string: [perl #84982]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=84982 >
Remove _new() from XS code and use _new() in Math::BigInt::Calc
instead. The XS _new() doesn't handle integers that are too large to
be represented exactly as floating point numbers, but small enough
to be represented as 64 bit integers. E.g., even with 64 bit integer
support, applying _num() to
18446744073709551615 (= 2**64-1) gives
1.
84467440737096e+19, not
18446744073709551615. The XS _new() also
returns nan, not inf, when it overflows. This closes RT #63335 and
RT #49569.
Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
XSRETURN(1); /* return x */
##############################################################################
-# Make a number (scalar int/float) from a BigInt object
-
-void
-_num(class,x)
- SV* x
- INIT:
- AV* a;
- NV fac;
- SV* temp;
- NV num;
- I32 elems;
- I32 index;
- NV BASE;
-
- CODE:
- a = (AV*)SvRV(x); /* ref to aray, don't check ref */
- elems = av_len(a); /* number of elems in array */
-
- if (elems == 0) /* only one element? */
- {
- ST(0) = *av_fetch(a, 0, 0); /* fetch first (only) element */
- XSRETURN(1); /* return it */
- }
- fac = 1.0; /* factor */
- index = 0;
- num = 0.0;
- BASE = XS_BASE;
- while (index <= elems)
- {
- temp = *av_fetch(a, index, 0); /* fetch current element */
- num += fac * SvNV(temp);
- fac *= BASE;
- index++;
- }
- ST(0) = newSVnv(num);
-
-##############################################################################
SV *
_zero(class)
use vars '$VERSION';
-$VERSION = '0.24_02';
+$VERSION = '0.25';
##############################################################################
# global constants, flags and accessory
-# announce that we are compatible with MBI v1.70 and up
-sub api_version () { 1; }
+# announce that we are compatible with MBI v1.83 and up
+sub api_version () { 2; }
# use Calc to override the methods that we do not provide in XS
for my $method (qw/
- str
+ str num
add sub mul div
rsft lsft
mod modpow modinv
_is_odd _is_even _is_one _is_zero
_is_two _is_ten
_zero _one _two _ten
- _acmp _len _num
+ _acmp _len
_inc _dec
__strip_zeros _copy
Separated from BigInt and shaped API with the help of John Peacock.
Fixed, sped-up and enhanced by Tels http://bloodgate.com 2001-2003.
Further streamlining (api_version 1 etc.) by Tels 2004-2007.
+Bug-fixing by Peter John Acklam E<lt>pjacklam@online.noE<gt> 2010-2011.
=head1 SEE ALSO