I'm trying to do an arithmetic operation involving big numbers using Math::BigInt
.
My intention is to multiply the variable k
by 4
and then subtract 1
. Below is my Perl file attempt MWE:
use strict;
use warnings;
use Math::BigInt;
my $k = '174224571863520493293247799005065324265473';
my $int = $k->bmuladd(4,-1);
printf ($int);
I get the following error message:
Can't locate object method "bmuladd" via package "2" (perhaps you forgot to load "2"?) at pv5.pl line 7.
Reading https://perldoc.perl.org/Math::BigInt#Arithmetic-methods, I could not understand something that helped solve this.
CodePudding user response:
You need to create a Math::BigInt
object using new
before you can use methods such as bmuladd
. Refer to the SYNOPSIS section of the doc:
use strict;
use warnings;
use Math::BigInt;
my $k = '174224571863520493293247799005065324265473';
my $x = Math::BigInt->new($k);
my $int = $x->bmuladd(4,-1);
print "$int\n";
Prints:
696898287454081973172991196020261297061891