Lines Matching defs:BigInt

1 package Math::BigInt;
9 # value: unsigned int with actual value (as a Math::BigInt::Calc or similiar)
18 my $class = "Math::BigInt";
69 # make cos()/sin()/exp() "work" with BigInt's or subclasses
156 my $CALC = 'Math::BigInt::Calc'; # module to do the low level math
162 my $EMU_LIB = 'Math/BigInt/CalcEmu.pm'; # emulate low-level math
175 tie $rnd_mode, 'Math::BigInt';
356 my $class = shift || 'Math::BigInt';
466 # create a new BigInt object from a string or another BigInt object.
601 # create a bigint 'NaN', if given a BigInt, set it to 'NaN'
633 # create a bigint '+-inf', if given a BigInt, set it to '+-inf'
668 # create a bigint '+0', if given a BigInt, set it to 0
711 # if given a BigInt, set it to +1 or -1, respecively
770 #$m->bstr() . 'e+' . $e->bstr(); # e can only be positive in BigInt
771 # 'e+' because E can only be positive in BigInt
792 # Make a "normal" scalar from a BigInt object
1370 # always true for BigInt, but different for BigFloats
2219 # (aka Math::BigInt). The latter shouldn't happen,though.
2225 # Math::BigInt::badd(1,2); => scalar x, scalar y
2229 # currently it tries 'Math::BigInt' + 1, which will not work.
2348 $lib = 'Math::BigInt::'.$lib if $lib !~ /^Math::BigInt/i;
2354 my @parts = split /::/, $lib; # Math::BigInt => Math BigInt
2355 my $file = pop @parts; $file .= '.pm'; # BigInt => BigInt.pm
2433 # convert a (ref to) big hex string to BigInt, return undef for error
2436 my $x = Math::BigInt->bzero();
2454 # convert a (ref to) big binary string to BigInt, return undef for error
2457 my $x = Math::BigInt->bzero();
2536 # internal calculation routines (others are in Math::BigInt::Calc etc)
2552 # may override it with special code (f.i. Math::BigInt::Constant does so)
2561 Math::BigInt - Arbitrary size integer math package
2565 use Math::BigInt;
2567 # or make it faster: install (optional) Math::BigInt::GMP
2571 use Math::BigInt lib => 'GMP';
2578 $x = Math::BigInt->new($str); # defaults to 0
2580 $nan = Math::BigInt->bnan(); # create a NotANumber
2581 $zero = Math::BigInt->bzero(); # create a +0
2582 $inf = Math::BigInt->binf(); # create a +inf
2583 $inf = Math::BigInt->binf('-'); # create a -inf
2584 $one = Math::BigInt->bone(); # create a +1
2585 $one = Math::BigInt->bone('-'); # create a -1
2621 $x->bnorm(); # normalize (no-op in BigInt)
2655 # The following do not modify their arguments in BigInt (are no-ops),
2664 my $gcd = Math::BigInt::bgcd(@values);
2666 my $lcm = Math::BigInt::blcm(@values);
2670 # latter is always 0 digits long for BigInt's
2672 $x->exponent(); # return exponent as BigInt
2673 $x->mantissa(); # return (signed) mantissa as BigInt
2674 $x->parts(); # return (mantissa,exponent) as BigInt
2676 $x->as_int(); # return as BigInt (in BigInt: same as copy())
2693 Math::BigInt->precision(); # get/set global P for all BigInt objects
2694 Math::BigInt->accuracy(); # get/set global A for all BigInt objects
2695 Math::BigInt->config(); # return hash containing configuration
2702 $i = new Math::BigInt '123_456_789_123_456_789';
2716 your input if you want BigInt to see all the digits:
2718 $x = Math::BigInt->new(12345678890123456789); # bad
2719 $x = Math::BigInt->new('12345678901234567890'); # good
2726 Currently, Math::BigInt::new() defaults to 0, while Math::BigInt::new('')
2730 $zero = Math::BigInt->bzero();
2731 $nan = Math::BigInt->bnan();
2733 C<bnorm()> on a BigInt object is now effectively a no-op, since the numbers
2734 are always stored in normalized form. If passed a string, creates a BigInt
2739 Output values are BigInt objects (normalized), except for bstr(), which
2758 print Dumper ( Math::BigInt->config() );
2759 print Math::BigInt->config()->{lib},"\n";
2769 Math::BigInt::Calc
2773 Math::BigInt
2800 $new_cfg = Math::BigInt->config( { trap_inf => 1, precision => 5 } );
2817 Math::BigInt->accuracy(undef);
2823 $y = Math::BigInt->new(1234567); # unrounded
2824 print Math::BigInt->accuracy(4),"\n"; # set 4, print 4
2825 $x = Math::BigInt->new(123456); # will be automatically rounded
2829 print Math::BigInt->accuracy(5),"\n"; # set to 5, print 5
2834 globals separated from Math::BigInt, but it is possible to subclass
2835 Math::BigInt and make the globals of the subclass aliases to the ones from
2836 Math::BigInt.
2849 Math::BigInt, passing a negative number precision has no effect since no
2857 Math::BigInt->precision(undef);
2863 $y = Math::BigInt->new(1234567); # unrounded
2864 print Math::BigInt->precision(4),"\n"; # set 4, print 4
2865 $x = Math::BigInt->new(123456); # will be automatically rounded
2868 globals separated from Math::BigInt, but it is possible to subclass
2869 Math::BigInt and make the globals of the subclass aliases to the ones from
2870 Math::BigInt.
2883 $x = Math::BigInt->new(10);
2885 $x = Math::BigInt->new(1234);
2891 $x = Math::BigInt->new(-5);
2899 $x = Math::BigInt->new($str,$A,$P,$R);
2901 Creates a new BigInt object from a scalar or another BigInt object. The
2909 $x = Math::BigInt->bnan();
2911 Creates a new BigInt object representing NaN (Not A Number).
2918 $x = Math::BigInt->bzero();
2920 Creates a new BigInt object representing zero.
2927 $x = Math::BigInt->binf($sign);
2929 Creates a new BigInt object representing infinity. The optional argument is
2938 $x = Math::BigInt->binf($sign);
2940 Creates a new BigInt object representing one. The optional argument is
2957 These methods all test the BigInt for beeing one specific value and return
2988 In BigInt, all numbers except C<NaN>, C<+inf> and C<-inf> are integers.
3160 Set $x to the integer less or equal than $x. This is a no-op in BigInt, but
3167 Set $x to the integer greater or equal than $x. This is a no-op in BigInt, but
3185 BigInt's, the length of the fraction part will always be 0.
3191 Return the exponent of $x as BigInt.
3197 Return the signed mantissa of $x as BigInt.
3201 $x->parts(); # return (mantissa,exponent) as BigInt
3211 Returns $x as a BigInt (truncated towards zero). In BigInt this is the same as
3237 Since version v1.33, Math::BigInt and Math::BigFloat have full support for
3381 or ffround, and never for BigInt (not implemented)
3414 * You can set the A global via C<< Math::BigInt->accuracy() >> or
3438 $x = Math::BigInt->new($number,$A,$P);
3440 * If no A or P is give ($x = Math::BigInt->new($number) form), then the
3448 C<< $x = Math::BigInt->new($number,undef,undef) >>:
3450 use Math::BigInt::SomeSubclass;
3451 use Math::BigInt;
3453 Math::BigInt->accuracy(2);
3454 Math::BigInt::SomeSubClass->accuracy(3);
3455 $x = Math::BigInt::SomeSubClass->new(1234);
3464 * Negative P is ignored in Math::BigInt, since BigInts never have digits
3466 * Math::BigFloat uses Math::BigInt internally, but setting A or P inside
3467 Math::BigInt as globals does not tamper with the parts of a BigFloat.
3598 C<Math::BigInt::Calc>. This is equivalent to saying:
3600 use Math::BigInt lib => 'Calc';
3604 use Math::BigInt lib => 'BitVect';
3606 The following would first try to find Math::BigInt::Foo, then
3607 Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:
3609 use Math::BigInt lib => 'Foo,Math::BigInt::Bar';
3611 Since Math::BigInt::GMP is in almost all cases faster than Calc (especially in
3613 no penalty if Math::BigInt::GMP is not installed, it is a good idea to always
3616 use Math::BigInt lib => 'GMP';
3634 C<mantissa()> and C<exponent()> return the said parts of the BigInt such
3655 use Math::BigInt;
3657 sub bint { Math::BigInt->new(shift); }
3659 $x = Math::BigInt->bstr("1234") # string "1234"
3661 $x = Math::BigInt->bneg("1234"); # BigInt "-1234"
3662 $x = Math::BigInt->babs("-12345"); # BigInt "12345"
3663 $x = Math::BigInt->bnorm("-0 00"); # BigInt "0"
3664 $x = bint(1) + bint(2); # BigInt "3"
3666 $x = bint(1); # BigInt "1"
3667 $x = $x + 5 / 2; # BigInt "3"
3668 $x = $x ** 3; # BigInt "27"
3669 $x *= 2; # BigInt "54"
3670 $x = Math::BigInt->new(0); # BigInt "0"
3671 $x--; # BigInt "-1"
3672 $x = Math::BigInt->badd(4,5) # BigInt "9"
3701 my $x = Math::BigInt->new('0b1'.'01' x 123);
3706 After C<use Math::BigInt ':constant'> all the B<integer> decimal, hexadecimal
3707 and binary constants in the given scope are converted to C<Math::BigInt>.
3712 perl -MMath::BigInt=:constant -e 'print 2**100,"\n"'
3720 use Math::BigInt qw/:constant/;
3727 do not work. You need an explicit Math::BigInt->new() around one of the
3730 use Math::BigInt;
3732 $x = Math::BigInt->new('1234567889123456789123456789123456789');
3735 constant at compile time and then hand the result to BigInt, which results in
3740 use Math::BigInt ':constant';
3760 to a constant overhead for all other operatons. So Math::BigInt does currently
3779 You can use an alternative library to drive Math::BigInt via:
3781 use Math::BigInt lib => 'Module';
3789 =head1 Subclassing Math::BigInt
3791 The basic design of Math::BigInt allows simple subclasses with very little
3800 reason for this is that Math::BigInt is optimized to call the object methods
3812 this is that Math::BigInt itself has a pluggable interface which permits it
3818 Math::BigInt if they need to change more basic behaviors. A subclass that
3840 This allows Math::BigInt to correctly retrieve package globals from the
3841 subclass, like C<$SubClass::precision>. See t/Math/BigInt/Subclass.pm or
3856 use Math::BigInt upgrade => 'Foo::Bar';
3861 use Math::BigInt upgrade => 'Math::BigFloat';
3903 The broot() function in BigInt may only work for small values. This will be
3908 Under Perl prior to 5.6.0 having an C<use Math::BigInt ':constant';> and
3915 Since eval(' use ...') can not be used in conjunction with ':constant', BigInt
3949 use Math::BigInt;
3951 my $x = new Math::BigInt 3*3;
3952 my $y = new Math::BigInt 3*3;
3968 as 1e+308. If in doubt, convert both arguments to Math::BigInt before
3973 use Math::BigInt;
3975 $x = Math::BigInt->new('1e56'); $y = 1e56;
3978 $y = Math::BigInt->new($y);
3987 C<int()> will return (at least for Perl v5.7.1 and up) another BigInt, not a
3990 $x = Math::BigInt->new(123);
3991 $y = int($x); # BigInt 123
3993 $y = int($x); # BigInt 123
3998 $y = $x->as_number(); # BigInt 123
4002 It is yet unlcear whether overloaded int() should return a scalar or a BigInt.
4008 $c = Math::BigInt->new(123);
4055 not change BigInt's way to do things. This is because under 'use integer' Perl
4057 system. If you need BigInt's behaving exactly like Perl's 'use integer', bug
4169 use Math::BigInt;
4185 Math::BigInt::bdiv() will always return a Math::BigInt, regardless whether
4250 L<Math::BigInt::BitVect>, L<Math::BigInt::Pari> and L<Math::BigInt::GMP>.