The explanation for what your PS identifies as a bug is simple
exp(90.0) > 3.4028235 x 10^38
and 3.4028235 x 10^38
is the largest positive number that a single-precision floating-point number can represent with any accuracy.
This analysis does, of course, assume that your variable x
is an IEEE 32-bit floating-point number.
Note too, that the expression ZDET-Z
will never, in single-precision, be different from 1.0
. 1.0 - 1.0e-20 == 0.9999999999999999999
but representing this exactly exceeds the precision available and the number is rounded to 1.0
.
While I still can't see how 1.-COST*COST
would ever be negative your use of floating-point arithmetic isn't reassuring me that there aren't subtle mistakes in those parts of the code you haven't shown us.