Math::BigInt(3p) Perl Programmers Reference Guide Math::BigInt(3p)
Math::BigInt(3p) Perl Programmers Reference Guide Math::BigInt(3p) # Math::BigInt(3p) Perl Programmers Reference Guide Math::BigInt(3p) NNAAMMEE # Math::BigInt - arbitrary size integer math package SSYYNNOOPPSSIISS # use Math::BigInt; # or make it faster with huge numbers: install (optional) # Math::BigInt::GMP and always use (it falls back to # pure Perl if the GMP library is not installed): # (See also the L<MATH LIBRARY> section!) # to warn if Math::BigInt::GMP cannot be found, use use Math::BigInt lib => 'GMP'; # to suppress the warning if Math::BigInt::GMP cannot be found, use # use Math::BigInt try => 'GMP'; # to die if Math::BigInt::GMP cannot be found, use # use Math::BigInt only => 'GMP'; my $str = '1234567890'; my @values = (64, 74, 18); my $n = 1; my $sign = '-'; # Configuration methods (may be used as class methods and instance methods) Math::BigInt->accuracy(); # get class accuracy Math::BigInt->accuracy($n); # set class accuracy Math::BigInt->precision(); # get class precision Math::BigInt->precision($n); # set class precision Math::BigInt->round_mode(); # get class rounding mode Math::BigInt->round_mode($m); # set global round mode, must be one of # 'even', 'odd', '+inf', '-inf', 'zero', # 'trunc', or 'common' Math::BigInt->config(); # return hash with configuration # Constructor methods (when the class methods below are used as instance # methods, the value is assigned the invocand) $x = Math::BigInt->new($str); # defaults to 0 $x = Math::BigInt->new('0x123'); # from hexadecimal $x = Math::BigInt->new('0b101'); # from binary $x = Math::BigInt->from_hex('cafe'); # from hexadecimal $x = Math::BigInt->from_oct('377'); # from octal $x = Math::BigInt->from_bin('1101'); # from binary $x = Math::BigInt->from_base('why', 36); # from any base $x = Math::BigInt->from_base_num([1, 0], 2); # from any base $x = Math::BigInt->bzero(); # create a +0 $x = Math::BigInt->bone(); # create a +1 $x = Math::BigInt->bone('-'); # create a -1 $x = Math::BigInt->binf(); # create a +inf $x = Math::BigInt->binf('-'); # create a -inf $x = Math::BigInt->bnan(); # create a Not-A-Number $x = Math::BigInt->bpi(); # returns pi $y = $x->copy(); # make a copy (unlike $y = $x) $y = $x->as_int(); # return as a Math::BigInt # Boolean methods (these don't modify the invocand) $x->is_zero(); # if $x is 0 $x->is_one(); # if $x is +1 $x->is_one("+"); # ditto $x->is_one("-"); # if $x is -1 $x->is_inf(); # if $x is +inf or -inf $x->is_inf("+"); # if $x is +inf $x->is_inf("-"); # if $x is -inf $x->is_nan(); # if $x is NaN $x->is_positive(); # if $x > 0 $x->is_pos(); # ditto $x->is_negative(); # if $x < 0 $x->is_neg(); # ditto $x->is_odd(); # if $x is odd $x->is_even(); # if $x is even $x->is_int(); # if $x is an integer # Comparison methods $x->bcmp($y); # compare numbers (undef, < 0, == 0, > 0) $x->bacmp($y); # compare absolutely (undef, < 0, == 0, > 0) $x->beq($y); # true if and only if $x == $y $x->bne($y); # true if and only if $x ! ...