Lines Matching defs:Math

1 package Math::BigInt;
9 # value: unsigned int with actual value (as a Math::BigInt::Calc or similiar)
18 my $class = "Math::BigInt";
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';
1984 # return the mantissa (compatible to Math::BigFloat, e.g. reduced)
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.
2251 # disable downgrading, because Math::BigFLoat->foo('1.0','2.0') needs floats
2348 $lib = 'Math::BigInt::'.$lib if $lib !~ /^Math::BigInt/i;
2354 my @parts = split /::/, $lib; # Math::BigInt => Math BigInt
2436 my $x = Math::BigInt->bzero();
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
2664 my $gcd = Math::BigInt::bgcd(@values);
2666 my $lcm = Math::BigInt::blcm(@values);
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';
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();
2758 print Dumper ( Math::BigInt->config() );
2759 print Math::BigInt->config()->{lib},"\n";
2769 Math::BigInt::Calc
2773 Math::BigInt
2775 Math::BigFloat
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
2833 Note: Works also for subclasses like Math::BigFloat. Each class has it's own
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
2867 Note: Works also for subclasses like Math::BigFloat. Each class has it's own
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);
2909 $x = Math::BigInt->bnan();
2918 $x = Math::BigInt->bzero();
2927 $x = Math::BigInt->binf($sign);
2938 $x = Math::BigInt->binf($sign);
3237 Since version v1.33, Math::BigInt and Math::BigFloat have full support for
3241 This section describes the accuracy/precision handling in Math::Big* as it
3305 Math::Round, is not implemented.)
3387 max($Math::BigFloat::div_scale,length(dividend)+length(divisor))
3414 * You can set the A global via C<< Math::BigInt->accuracy() >> or
3415 C<< Math::BigFloat->accuracy() >> or whatever class you are using.
3416 * You can also set P globally by using C<< Math::SomeClass->precision() >>
3419 * to undefine A, use C<< Math::SomeCLass->accuracy(undef); >>
3420 * to undefine P, use C<< Math::SomeClass->precision(undef); >>
3421 * Setting C<< Math::SomeClass->accuracy() >> clears automatically
3422 C<< Math::SomeClass->precision() >>, and vice versa.
3427 * to find out the current global A, use C<< Math::SomeClass->accuracy() >>
3428 * to find out the current global P, use C<< Math::SomeClass->precision() >>
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.
3468 A flag is used to mark all Math::BigFloat numbers as 'never round'.
3491 * Thus you can have the math done by on Math::Big* class in two modi:
3502 $x = Math::BigFloat->new(12.34);
3503 $y = Math::BigFloat->new(98.76);
3513 all-the-same-P modes. For example, Math::Currency might set A to undef,
3554 * you can set/get the global R by using C<< Math::SomeClass->round_mode() >>
3555 or by setting C<< $Math::SomeClass::round_mode >>
3564 $x = Math::BigFloat->new(123.456);
3597 Math with the numbers is done (by default) by a module called
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';
3647 with Math::BigFloat's internal representation of a zero as C<0E1>).
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"
3670 $x = Math::BigInt->new(0); # BigInt "0"
3672 $x = Math::BigInt->badd(4,5) # BigInt "9"
3677 use Math::BigFloat;
3680 $x = Math::BigFloat->new(123.4567);
3681 $y = Math::BigFloat->new(123.456789);
3682 Math::BigFloat->accuracy(4); # no more A than 4
3686 Math::BigFloat->round_mode('odd'); # round to odd
3688 Math::BigFloat->accuracy(5); # no more A than 5
3689 Math::BigFloat->round_mode('odd'); # round to odd
3694 Math::BigFloat->accuracy(undef); # A not important now
3695 Math::BigFloat->precision(2); # P important
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>.
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');
3740 use Math::BigInt ':constant';
3745 will print nothing but newlines. Use either L<bignum> or L<Math::BigFloat>
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
3842 t/Math/BigFloat/SubClass.pm completely functional subclass examples.
3849 you like, you can change part of the overloading, look at Math::String for an
3856 use Math::BigInt upgrade => 'Foo::Bar';
3859 the class Foo::Bar. Usually this is used in conjunction with Math::BigFloat:
3861 use Math::BigInt upgrade => 'Math::BigFloat';
3908 Under Perl prior to 5.6.0 having an C<use Math::BigInt ':constant';> and
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);
3990 $x = Math::BigInt->new(123);
3992 $x = Math::BigFloat->new(123.45);
3997 $x = Math::BigFloat->new(123.45);
4000 This also works for other subclasses, like Math::String.
4008 $c = Math::BigInt->new(123);
4105 $x = Math::BigFloat->new(5);
4169 use Math::BigInt;
4170 use Math::BigFloat;
4172 $mbf = Math::BigFloat->new(5);
4173 $mbi2 = Math::BigInteger->new(5);
4174 $mbi = Math::BigInteger->new(2);
4185 Math::BigInt::bdiv() will always return a Math::BigInt, regardless whether
4186 the result should be a Math::BigFloat or the second operant is one.
4188 To get a Math::BigFloat you either need to call the operation manually,
4190 via Math::BigFloat->new():
4192 $float = Math::BigFloat->new($mbi2) / $mbi; # = 2.5
4197 $float = Math::BigFloat->new($mbi2 / $mbi); # = 2.0 thus wrong!
4202 $integer = $mbi2 / Math::BigFloat->new($mbi); # ditto
4214 This section also applies to other overloaded math packages, like Math::String.
4227 $x = Math::BigFloat->new(12);
4228 Math::BigFloat->precision(0);
4229 Math::BigFloat->round_mode('even');
4232 Math::BigFloat->precision(2);
4249 L<Math::BigFloat>, L<Math::BigRat> and L<Math::Big> as well as
4250 L<Math::BigInt::BitVect>, L<Math::BigInt::Pari> and L<Math::BigInt::GMP>.
4256 L<http://search.cpan.org/search?mode=module&query=Math%3A%3ABigInt> contains