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 ##############################################################################
19 # global constants, flags and accessory
21 # constants for easier life
24 ##############################################################################
25 # create objects from various representations
29 # (string) return ref to num
31 my $x = $$d; # make copy
37 my $x = 0; return \$x;
42 my $x = 1; return \$x;
52 # catch and throw away
55 ##############################################################################
56 # convert back to string and number
71 ##############################################################################
99 my $u = int($$x / $$y); my $r = $$x % $$y; $$x = $u;
100 return ($x,\$r) if wantarray;
107 my $u = $$x ** $$y; $$x = $u;
114 my $u = int($$x) & int($$y); $$x = $u;
121 my $u = int($$x) ^ int($$y); $$x = $u;
128 my $u = int($$x) | int($$y); $$x = $u;
135 my $u = int($$x)+1; $$x = $u;
142 my $u = int($$x)-1; $$x = $u;
146 ##############################################################################
152 return ($$x <=> $$y);
157 return length("${$_[1]}");
162 # return the nth digit, negative values count backward
163 # 0 is the rightmost digit
166 $n ++; # 0 => 1, 1 => 2
167 return substr($$x,-$n,1); # 1 => -1, -2 => 2 etc
170 ##############################################################################
175 # return true if arg is zero
177 return ($$x == 0) <=> 0;
182 # return true if arg is even
184 return (!($$x & 1)) <=> 0;
189 # return true if arg is odd
191 return ($$x & 1) <=> 0;
196 # return true if arg is one
198 return ($$x == 1) <=> 0;
201 ###############################################################################
202 # check routine to test internal state of corruptions
206 # no checks yet, pull it out from the test suite
208 return "$x is not a reference" if !ref($x);
217 Math::BigInt::Scalar - Pure Perl module to test Math::BigInt with scalars
221 Provides support for big integer calculations via means of 'small' int/floats.
222 Only for testing purposes, since it will fail at large values. But it is simple
223 enough not to introduce bugs on it's own and to serve as a testbed.
227 Please see Math::BigInt::Calc.
231 This program is free software; you may redistribute it and/or modify it under
232 the same terms as Perl itself.
236 Tels http://bloodgate.com in 2001.
240 L<Math::BigInt>, L<Math::BigInt::Calc>.