Odd Behavior Returns NaN - Bug??

I have a line in a code statement that computes this ...

rtn2 = -(((2*kR - 1)*exp(2*kR)+1)*exp(-2*kR)*ksq*exp(-2*kappa*z))/4


I am getting something very odd in behavior and wondered if someone might check behind for me. Here is a debug report.

print z, kR, ksq, kappa, rtn2
---
  0.006  316.228  115.849  31.6228  -12513.3
  0.006  398.107  115.849  39.8107  NaN

print  -(((2*398 - 1)*exp(2*398)+1)*exp(-2*398)*116*exp(-2*39.8*0.006))/4
  NaN


I set up the function in Maple and get this ...

frtn2:=proc(kR,ksq,ka,z) ....
---
evalf(frtn2(316, 116, 31.6, 0.006)) = -12523.99512
evalf(frtn2(398, 116, 39.8, 0.006)) = -14300.33074


I find the behavior as a return NaN very confusing.

Igor 6.35A on Mac 10.9.5.
According to my reckoning, exp(2*398)=exp(796)=10^345.7

The largest floating-point exponent in IEEE double-precision floating point is 307.95 ( 2^1023).

Since your exponent (345.7) exceeds the IEEE max, I would expect some kind of error.
Oh! Yes.

I will have to find a clever way around this. Or perhaps the orders of magnitudes on my inputs are ... way off.

Thanks!

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
print  -(   (  (2*398 - 1)*1+ exp(-2*398)  )   *116*exp(-2*39.8*0.006)   )/4
  -14300.3


I simply multiplied your first two exponential parenthetical expressions. Apparently underflow is not an issue. Note also that the Maple result was obtained, presumably because of some symbolic pre-manipulation.

Is there an intentional discrepancy between your early arguments (398) and the final one (39.8) ?
Thank you. That holds the rtn2 term for a bit further in the parameter set.

After that, I have an approximation that can take over (basically, it is the limit of the exact expression as kR --> infinity)

This would make an interesting assignment for an course on numerical methods and computer tools ... "Examples of When Your Computer Programming Tool is Not God". Good thing I had some 8 bit Fortran programming experience in my background to understand the history behind the limitation here. :-)

Much obliged for the quick response on a Sunday night!

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville