LoginSignup
0

More than 3 years have passed since last update.

posted at

updated at

Organization

Perlで平方根を子供が生まれた年の桁数程度求めるには

bignumというパッケージを使うと出来ました。

求めたい桁数は、bignumを宣言する際のpオプションで指定するようで、
任意のタイミングで変えることは出来ないようです。

以下で、2013(次男の生れた年)の平方根を2013桁求まります。
(実際2013桁必要な場合、更に桁数を増やして計算した結果を使った
ほうが正確です。有効数字とかでググれば理解できるのかなぁ)

use bignum(p => -2013);
$a= sqrt(2013);
print "Ans = $a\n";

求める桁数を任意のタイミングで変えるには

Math::BigFloatを使うとできる。先ほどのbignumでは一度設定した
桁数を変更できない模様。

use Math::BigFloat;

$x = Math::BigFloat->new(2013);
$x->precision(-2013);
print $x->bsqrt();

参考リンク

関連投稿

関連記事

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0