Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

for __ in $$; do perl -Mbignum -le 'print 7 ** 127 % 524287 ' perl -Mbignum -le 'print ( 7 ** 127 ) % ( 524287 )' echo ' ( 7 ^ 127 ) % 524287 ' | bc done | gcat -b 1 102010 2 212545092456801670844330383105896224333193816736399849985499 +757869483902203328714236393937418376186556719543 3 102010
How come adding parenthesis screws up the calculation here ? The middle one simply outputted 7 ** 127 without modulating it down

The equation being tested is Mersenne Primes

    ( M3 ** M7 ) mod M19
Thanks.
perl -V Summary of my perl5 (revision 5 version 36 subversion 1) configuration +: Platform: osname=darwin osvers=22.4.0 archname=darwin-thread-multi-2level uname='darwin ventura-arm64.local 22.4.0 darwin kernel version 22. +4.0: mon mar 6 20:55:35 pst 2023; root:xnu-8796.101.5~3release_arm64_ +vmapple arm64 '

Replies are listed 'Best First'.
Re: bignum and parenthesis
by tybalt89 (Monsignor) on Jul 03, 2023 at 18:11 UTC

    Use

    perl -Mbignum -le 'print +( 7 ** 127 ) % ( 524287 )'

    See beginning of perlfunc for reason.

      Reading the documentation is a good recommendation, but to spell it out quickly, print is a function, not a keyword, and perl functions have optional parentheses around the arguments.
        "Reading the documentation is a good recommendation, but to spell it out quickly, print is a function, not a keyword, and perl functions have optional parentheses around the arguments." then what does the parser think the modulo and number is doing there? from my trial and error it seems it's trying to do modulo using the return value of print function ( = "1" ) , which is a very odd way to interpret such a syntax, since there's no subsequent action to further process that info, store it in a variable, or output to the pipe / to file.

      Oh that's why!

      Of course, perl -wle '...' catches it. Yay warnings!