Upcoming SlideShare
×

# Perlで任意精度計算

2,365 views
2,270 views

Published on

YAPC::Asia Tokyo 2010 presentation

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
2,365
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

• ### 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% --