Hi guys...
I am loving this integer maths thing.
64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform.
Using one of the 'Brothers' methods, URL inside the code.
#!/bin/sh
#
# #!/usr/local/bin/dash
# e_constant.sh
# Brother's formula [2].
# http://www.brotherstechnology.com/math/e-formulas.html
# e=2.718281828459045 from Python 3.8.0.
# Google's value, e=2.71828182846.
#
# For *NIX 64 bit or greater systems, 32 bit systems commented out.
# (Also tested on AMIGA OS_3.1 using ADE the UNIX emulator and ksh88.)
echo ""
echo "Calculate e to 14+ decimal places, 64 bit, (7+ decimal places, 32 bit),"
echo "integer maths inside 'dash' or 'sh'."
echo ""
initial_e=0
# 32 bit version for AMIGA ADE.
# e=200000000
# Default 64 bit version.
e=2000000000000000
k=0
factorial=1
diff=$(( e - initial_e ))
while [ ${diff} -gt 1 ]
do
initial_e=${e}
k=$(( k + 1 ))
factorial=$(( factorial * 2 * k * (2 * k + 1) ))
# 32 bit version.
# e=$(( e + (((2 * k + 2) * 100000000) / factorial) ))
# Default 64 bit version.
e=$(( e + (((2 * k + 2) * 1000000000000000) / factorial) ))
diff=$(( e - initial_e ))
done
# 32 bit version.
# printf "%.8f\n" $(( e ))e-8
# Default 64 bit version.
result=$( printf "%.15f\n" $(( e ))e-15 )
# Result: 2.718281828459041
echo "${result}"
echo ""
echo "Python 3.8.0 value, e = 2.718281828459045."
echo "Number of iterations = ${k}."
echo ""
Result in 64 bit mode, my usual platform.
Last login: Sun Oct 13 15:21:17 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./e_constant.sh
Calculate e to 14+ decimal places, 64 bit, (7+ decimal places, 32 bit),
integer maths inside 'dash' or 'sh'.
2.718281828459041
Python 3.8.0 value, e = 2.718281828459045.
Number of iterations = 9.
AMIGA:amiga~/Desktop/Code/Shell> _