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
74 # catch and throw away
77 ##############################################################################
78 # convert back to string and number
152 sprintf("0x%x",${$_[1]});
157 sprintf("0b%b",${$_[1]});
160 ##############################################################################
188 my $u = int($$x / $$y); my $r = $$x % $$y; $$x = $u;
189 return ($x,\$r) if wantarray;
196 my $u = $$x ** $$y; $$x = $u;
203 my $u = int($$x) & int($$y); $$x = $u;
210 my $u = int($$x) ^ int($$y); $$x = $u;
217 my $u = int($$x) | int($$y); $$x = $u;
224 my $u = int($$x)+1; $$x = $u;
231 my $u = int($$x)-1; $$x = $u;
235 ##############################################################################
241 return ($$x <=> $$y);
246 return length("${$_[1]}");
251 # return the nth digit, negative values count backward
252 # 0 is the rightmost digit
255 $n ++; # 0 => 1, 1 => 2
256 return substr($$x,-$n,1); # 1 => -1, -2 => 2 etc
259 ##############################################################################
264 # return true if arg is zero
271 # return true if arg is even
278 # return true if arg is odd
285 # return true if arg is one
292 # return true if arg is one
299 # return true if arg is one
304 ###############################################################################
305 # check routine to test internal state of corruptions
309 # no checks yet, pull it out from the test suite
311 return "$x is not a reference" if !ref($x);
320 Math::BigInt::Scalar - Pure Perl module to test Math::BigInt with scalars
324 Provides support for big integer calculations via means of 'small' int/floats.
325 Only for testing purposes, since it will fail at large values. But it is simple
326 enough not to introduce bugs on it's own and to serve as a testbed.
330 Please see Math::BigInt::Calc.
334 This program is free software; you may redistribute it and/or modify it under
335 the same terms as Perl itself.
339 Tels http://bloodgate.com in 2001.
343 L<Math::BigInt>, L<Math::BigInt::Calc>.