1 ###############################################################################
2 # core math lib for BigInt, representing big numbers by normal int/float's
3 # for testing only, will fail any bignum test if range is exceeded
5 package Math::BigInt::Scalar;
9 # use warnings; # dont use warnings for older Perls
13 use vars qw/@ISA $VERSION/;
18 sub api_version() { 1; }
20 ##############################################################################
21 # global constants, flags and accessory
23 # constants for easier life
26 ##############################################################################
27 # create objects from various representations
31 # create scalar ref from string
33 my $x = $d; # make copy
79 # catch and throw away
82 ##############################################################################
83 # convert back to string and number
157 sprintf("0x%x",${$_[1]});
162 sprintf("0b%b",${$_[1]});
167 sprintf("0%o",${$_[1]});
170 ##############################################################################
198 my $u = int($$x / $$y); my $r = $$x % $$y; $$x = $u;
199 return ($x,\$r) if wantarray;
206 my $u = $$x ** $$y; $$x = $u;
213 my $u = int($$x) & int($$y); $$x = $u;
220 my $u = int($$x) ^ int($$y); $$x = $u;
227 my $u = int($$x) | int($$y); $$x = $u;
234 my $u = int($$x)+1; $$x = $u;
241 my $u = int($$x)-1; $$x = $u;
245 ##############################################################################
251 return ($$x <=> $$y);
256 return length("${$_[1]}");
261 # return the nth digit, negative values count backward
262 # 0 is the rightmost digit
265 $n ++; # 0 => 1, 1 => 2
266 return substr($$x,-$n,1); # 1 => -1, -2 => 2 etc
269 ##############################################################################
274 # return true if arg is zero
281 # return true if arg is even
288 # return true if arg is odd
295 # return true if arg is one
302 # return true if arg is one
309 # return true if arg is one
314 ###############################################################################
315 # check routine to test internal state of corruptions
319 # no checks yet, pull it out from the test suite
321 return "$x is not a reference" if !ref($x);
330 Math::BigInt::Scalar - Pure Perl module to test Math::BigInt with scalars
334 Provides support for big integer calculations via means of 'small' int/floats.
335 Only for testing purposes, since it will fail at large values. But it is simple
336 enough not to introduce bugs on it's own and to serve as a testbed.
340 Please see Math::BigInt::Calc.
344 This program is free software; you may redistribute it and/or modify it under
345 the same terms as Perl itself.
349 Tels http://bloodgate.com in 2001 - 2007.
353 L<Math::BigInt>, L<Math::BigInt::Calc>.