diff options
| -rw-r--r-- | challenge-021/steven-wilson/perl5/ch-01.pl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-021/steven-wilson/perl5/ch-01.pl b/challenge-021/steven-wilson/perl5/ch-01.pl new file mode 100644 index 0000000000..a985076177 --- /dev/null +++ b/challenge-021/steven-wilson/perl5/ch-01.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +# Author: Steven Wilson +# Date: 2019-08-12 +# Week: 021 +# +# Task #1 +# +# Write a script to calculate the value of e, also known as Euler’s +# number and Napier’s constant. Please checkout wiki page for more +# information. +# https://en.wikipedia.org/wiki/E_(mathematical_constant) + +use strict; +use warnings; +use feature qw/ say /; +use Math::BigFloat; + +my $number = 0; +my $factorial = 1; +my $e = Math::BigFloat->new( 1 / $factorial ); +my $previous_e = 0; + +while ( $e != $previous_e ) { + # say $e; + $number++; + $factorial *= $number; + $previous_e = $e->copy(); + $e += ( 1 / $factorial ); +} + +my $dp = 50; +say "value of e to $dp decimal places: ", $e->fround($dp); |
