我想知道如何将$c
转换回内置浮点数。我已阅读Math::BigInt
,Math::BigRat
和Math::BigFloat
的文档。有一些函数可以对数字进行舍入,但我无法弄清楚如何将其强制转换为浮点数,同时保留尽可能高的精度。
use strict;
use warnings;
use Math::BigInt;
use Math::BigRat;
my $a = Math::BigInt::->new(400);
my $b = Math::BigInt::->new(3);
my $c = 2 ** (Math::BigRat::->new($a)/$b);
答案 0 :(得分:2)
您需要numify()
方法:
use strict;
use warnings;
use Math::BigInt;
use Math::BigRat;
my $a = Math::BigInt->new(400);
my $b = Math::BigInt->new(3);
my $c = 2 ** (Math::BigRat->new($a)/$b);
print $c, "\n";
print $c->numify(), "\n";
输出:
13719325343735719921671695695860836966789
1.37193253437357e+40