new#
Build a Math::GMP object from a string or integer scalar.
Synopsis#
my $x = Math::GMP->new(123);
my $y = Math::GMP->new('123456789012345678901234567890');
my $z = Math::GMP->new('abcd', 36); # base 36
What you get back#
A blessed reference of class Math::GMP. You can feed it to any overloaded operator, or to the named methods on this page.
The first argument is read as a string. A leading + is stripped, and embedded spaces and underscores are removed — so '1_000_000' and ' 1 000 000 ' both parse. When no base is given the string must match /^-?[\dxA-Fa-f]+$/, which admits the usual 0x-prefixed hex form; anything else croaks with Argument to Math::GMP->new is not a string representing an integer. With an explicit base (2–36) the usual GMP digit-set applies.
Edge cases#
Missing or false first argument →
Math::GMPof0.Floating-point input is not special-cased here; you get whatever
libgmp’s parser makes of the stringified value.Base
0(the default) means «guess from the prefix»:0x→ hex,0→ octal, otherwise decimal.