1

I'm in C++ and I'm using the exponential function exp() from <cmath>. I'm dealing with very small number, so I tried to use also expl() fucntion, but the (incorrect) result is always the same: 1. I show you a very quick example. How can I solve this problem? Thanks.

#include <cmath>
...
long double a= 1.40543081e-8;
cout << "exp(-a)= " << exp(-a) << endl; 
cout << "expl(-a)= " << expl(-a) << endl;

The output is:

exp(-a)= 1  
expl(-a)= 1

Thanks for help.

fslack
  • 189
  • 9
  • The result is correct, it's only printed with too few decimal places, thus getting rounded to 1. See also [this question](https://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout). – Lukas-T Apr 11 '21 at 11:20
  • 1
    If you know the value is very small, use expm1 to avoid loss of significance. – Raymond Chen Apr 11 '21 at 13:15

0 Answers0