[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] pi



Pi is an irrational number. Defining it as a ratio only produces an 
approximation.  22/7 only give you the first TWO signifigant digits with 
any accuracy.  355/113 is slightly better giving the first six 
signifigant digits accurately.  These were FINE for much of the last 3000 
years, but nowdays there's often need for more accurate values of pi.

Canonically, pi = atan2(1,1) * 4.0, which should produce pi to the 
accuracy of double floats.  If you need more accurate pi, you're probably 
doing something mathematically interesting.

#!perl -w

use strict;
use vars qw($pi_approx $pi_better $pi);
use constant PI => atan2(1,1) * 4.0;

$pi_approx = 22/7;
$pi_better = 355/113;
$pi        = PI;

print "$pi_approx\n";
print "$pi_better\n";
print "$pi\n";

__END__

Back when I was doing electronics as a living, we just used 3.1416 as pi, 
which is really just three signifigants with the fourth rounded up.  In 
general, one doesn't need more than three digits accuracy, but some 
applications demand more.

--B

# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org