EXP failure with very small negative value

My model crashes at this single line of code, with an erroneous arithmetic operation statement (preceded by the statement Floating-point exception) :

gcc1  = exp(-84.165_DP / t9a13)

I have trapped the value of t9a13 at 0.271320760

Now, this does produce an arithmetic result of 1.9044538286107083174449719800094e-135 but, obviously, not within my model.

I am assuming that this is down to the very small nature of the resultant value, though I do have -ffpe-trap set to trap invalid, zero, overflow and underflow errors and would have thought that this is might result in an underflow error?

The full error message that precedes the traceback is Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

The input values are correct.

Am I correct in my assumption and, more importantly, is there a way of resolving this (given that several of my OS calculators do produce a valid, though very small, value)?

Both variables have been declared as real(DP) :: gcc1, t9a13 with DP being defined as integer, parameter :: DP = kind(0d0).

1 Like

This code works on my side with GFortran, with no compiler option.

It also gives a correct result with -184.165_DP, and with -284.165_DP it finally prints 0.0000000000000000

1 Like

Thank you. I am doing another run with the code; I think I may have spotted the error.

Basically, the actual variable definition was real :: gcc1, t9a13 and not real(DP) :: gcc1, t9a13; as I had it in my example above and in the code model I was looking at at the time. I realised my error (looking at the wrong model) only when I went through a re-check due to your reply - so, again, thank you.

2 Likes

Again default kinds malediction…

Yeah take a look at this thread for similar issue/explanation https://fortran-lang.discourse.group/t/can-floating-point-literals-be-adapted-by-the-compiler-to-double-precision-variable/