Provide a very nice approximation for the value of ex


All of you are familiar with the transcendental number, e. Many applications in mathematics involve computing various powers of e. It can be proven that 
ex = 1 + x/1 + x2/2! + x3/3! + ...

for all values of x. Of course, this is an infinite sum, so we can't hope to actually sum all of these values up! But the good news is that the later terms get so small that a partial sum can provide a very nice approximation for the value of ex. You are to write a single precision function (result returned in $f0) called exp with one single precision parameter (in $f12), along with a little driver program for testing your function. Your function should use the summation formula as an approximation for the value of ex, using the following guide for terminating the summation:
If the next term divided by the summation so far is less that 1.0e-15, then terminate the summation (and don't even bother to add in that next term). [One might be tempted to just stop if the next term is less that 1.0e-15, but my proposed guide is more sensitive to the relative size of the actual summation.]
Even though the summation is valid for all values of x, there is a problem with convergence when you use negative values too small such as -20. Therefore, your exp function should compute the value of e|x| instead, and then invert the result (this process should be handled by the function exp, not by your driver program).
You can expect your program to have overflow problems when tested with values of x somewhere around 90 or -90 (Why?).
Here is a sample execution of my code, and your output should have exactly the same format:
Let's test our exponential function!
Enter a value for x (or 999 to exit): 9
Our approximation for e^9.00000000 is 8103.08300781 
Enter a value for x (or 999 to exit): 0
Our approximation for e^0.00000000 is 1.00000000 
Enter a value for x (or 999 to exit): 3.75
Our approximation for e^3.75 is 42.52108002 
Enter a value for x (or 999 to exit): -1
Our approximation for e^-1.00000000 is 0.36787942 
Enter a value for x (or 999 to exit): 80
Our approximation for e^80.00000000 is 55406214943247279000000000000000000.00000000
Enter a value for x (or 999 to exit): 999
Come back soon!

Submit a separate file called HW7exp_PGavin.asm, if your name is Peter Gavin.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Provide a very nice approximation for the value of ex
Reference No:- TGS0116518

Now Priced at $25 (50% Discount)

Recommended (96%)

Rated (4.8/5)