Floating Point Errors

I’m getting these errors when I try to run an old code on a 64-bit machine with the 64-bit PGI compiler:

Line 673–> chi1 = 8.0sqrt(pi/elmass)avgcharge**4/(3.(2.boltz)1.5)
Line 674–> chi2 = log(boltz
3/(pi
avg*charge**6))

pgf77 -c -g -C -O npchemin.f
PGFTN-W-0130-Floating point underflow. Check constants and constant expressions (npchemin.f: 673)
PGFTN-W-0130-Floating point underflow. Check constants and constant expressions (npchemin.f: 674)
PGFTN-W-0132-Floating pt. invalid oprnd. Check constants and constant expressions (npchemin.f: 674)
0 inform, 3 warnings, 0 severes, 0 fatal for npchemin
PGFTN/x86-64 Linux 7.1-6: compilation completed with warnings

These are defined in a file name npcomon:

BOLTZ=1.380622D-23
PI=3.1415926536
AVG=6.022169D+26
BOLTZ=1.380622D-23

I tried changing from “E” to “D” in the constants.

This code has run fine in the past on a 32-bit SGI machine. I get the same errors using the 32-bit PGI compiler.

I get a “floating exception” error. If I add the -Ktrap=inv,unf,fp flags, I get a NaN followed by a segmentation fault.

Hi Bill,

The compiler will attempt to optimize constant expressions by calculating the expressions at compile time. Given that the code is attempting divide a very large number by a very small number (and vice-versa), the underflow is not unexpected. You might try setting the default kind for REAL constants to 8 by adding the flag “-r8”. Though given the large delta, you may still get an underflow.

I get a “floating exception” error. If I add the -Ktrap=inv,unf,fp flags, I get a NaN followed by a segmentation fault.

I think the floating point exception would be expected here since you’re most liking getting an “INF” value. Again, try “-r8” to see it it helps.

  • Mat