Math-MPFR

 view release on metacpan or  search on metacpan

demos/euler.p  view on Meta::CPAN

#################################################################################
# This script requires Math::GMPq, Math::GMPz, and Math::MPFR.                  #
# It calculates the euler number e (2.7182818...), correct to $ARGV[0] bits.    #
# The calculated value is displayed unless $ARGV[1] is both provided and false. #
# With each iteration of the for{} loop (below) we get closer and closer to     #
# the actual value of e. Furthermore, with successive iterations of the for{}   #
# loop, the values alternate between "less than e" and "greater than e".        #
# Hence the actual (irrational) value of e is always between the values         #
# calculated by successive iterations of the for{} loop.                        #
#                                                                               #
# Of course, the simplest and most efficient way to get the value of e, to      #
# $ARGV[0] bits is simply to do:                                                #
#   Rmpfr_exp($rop, Math::MPFR->new(1), MPFR_RNDN)                              #
# where $rop is a $ARGV[0]-bit precision Math::MPFR object.                     #
# But doing it that way is a bit less interesting.                              #
#                                                                               #
# The same for{} loop can be also used to calculate the exact probabilities of  #
# "winning" at a simplistic solitaire-type card game. See demos/solitaire.p     #
# in the Math::GMPz source distro.                                              #



( run in 2.646 seconds using v1.01-cache-2.11-cpan-71847e10f99 )