I am trying to plot the logarithmic function: x*log(1+1/x) for very large values of x. I have checked for few terms since the overall plot was not good and the problem seems to be that although this function should never be higher than 1, for some points it becomes larger than 1. I believe it has something to do with accuracy of the log function.
for the following values of x:
[ 5.4380181e+11 3.1688845e+12 4.5195668e+13 7.4634268e+14 1.2442192e+16
2.0754228e+17 3.4624427e+18 5.787843e+19 9.9925409e+20 2.6069079e+22]
I get for x*np.log(1+1/x):
[ 0.99999999 0.99999989 0.99999774 0.9999925 0.99959801 0.99007829
1.1261964 0.0 0.0 0.0]
As you can see the 7th term is bigger than 1.
I have tried using log1p instead but that gives non-sensical answers.
I have also tried using np.float128() but I get exactly the same results as above.
Any ideas?
Thanks a lot!
log1p? It should be able to give the correct result.