Seu SlideShare está sendo baixado. ×

# Perlで任意精度計算

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Vcs29
Carregando em…3
×

1 de 53 Anúncio

# Perlで任意精度計算

YAPC::Asia Tokyo 2010 presentation

YAPC::Asia Tokyo 2010 presentation

Anúncio
Anúncio

Anúncio

Anúncio

### Perlで任意精度計算

1. 1. 3.14159 26535 89793 23846 26433 83279 50288.....
2. 2. use Math::BigFloat; my \$x = Math::BigFloat->new(‘3.1415...’); my \$y = Math::BigFloat->new(‘2.718281...’); my \$z = \$x * \$y;
3. 3. # my \$pi = Math::BigFloat->new(3.141592...); # my \$pi = Math::BigFloat->new(‘3.141592...’);
4. 4. use strict; use Math::BigFloat; use Benchmark qw(cmpthese); cmpthese -1, {     plain => sub {         my \$x = rand(10);         my \$y = rand(10);         my \$z = rand(10);         (\$x + \$y ) * \$z;     },     bigfloat => sub {         my \$x = rand(10);         my \$y = rand(10);         my \$z = rand(10);         (Math::BigFloat->new(\$x) + Math::BigFloat->new(\$y)) * Math::BigFloat->new(\$z);     }, };
5. 5. daisuke@beefcake ~\$ perl foo.pl               Rate bigfloat plain bigfloat 3380/s -- -100% plain 2383127/s 70403% -- daisuke@beefcake ~\$ perl foo.pl               Rate bigfloat plain bigfloat 3380/s -- -100% plain 2360644/s 69738% -- daisuke@beefcake ~\$ perl foo.pl               Rate bigfloat plain bigfloat 3380/s -- -100% plain 2406041/s 71081% --
6. 6. > perl benchmark.pl Rate bigfloat plain bigfloat 3901/s -- -100% plain 2338582/s 59849% --
7. 7. •DateTime::Util::Calc •DateTime::Util::Astro •DateTime::Event::Lunar
8. 8. my \$v = ( \$x + \$y ) * \$z; #include <mpfr.h> mpfr_t x, y, z, w; mpfr_add( w, x, y, MPFR_RNDN ); mpfr_mul( w, w, z, MPFR_RNDN );
9. 9. mpfr_add( w, x, y, MPFR_RNDN );
10. 10. s/iter bigint xs bigint 2.58 -- -98% mpfr 4.70e-02 5394% --