How can I get numbers from Perl bignum?

I have a really large number in Perl. I use "bignum". How can I extract single digits from this large number. For example, if I have a number like this, and that get the 3rd digit from the end:

1029384710985234058763045203948520945862986209845729034856

-> 8

+3
source share
2 answers

bignums are transparently available, so this will work:

$digit = substr($bignum, -3, 1);
+11
source

The package bignumuses Math::BigIntunder the hood for integers.

On the Math::BigIntman page :

$x->digit($n);        # return the nth digit, counting from right

Note that counting starts from zero for the rightmost digit.

+8
source

Source: https://habr.com/ru/post/1710996/


All Articles