Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Write small numbers as zero

ed_c_
Beginner
862 Views

Hi All

I have inherited a fortran program from somebody and have run into a situation where it prints very small numbers out with the write statement, something like -8.97639E-30 or 7.36475-173. How can I get the program to write numbers under a certain threshold value to be zero without having to trawl through the code and do a check everywhere. Is there a compiler option I can use for instance?

Thanks in advance

Ed

0 Kudos
3 Replies
Steve_Lionel
Honored Contributor III
862 Views

There is not such an option. I assume that -173 exponent value is double-precision, as I don't think a denormalized single will go that small.

0 Kudos
jimdempseyatthecove
Honored Contributor III
862 Views

You will have to dig through your program because either the FORMAT edit descriptors (or lack thereof with *), are specifying that the print is to supply the exponents of such small (or large) numbers. IOW has E, EN, ES or G formatting. Change these to F formatting (Fw.d). This transfers real numbers without exponent.

If you really want exponents printed, except for very small numbers, then you will need to qualify a cutoff point. For this, often one writes a specialized formatting subroutine that handles, in your case, very small numbers.

Jim Dempsey

0 Kudos
mecej4
Honored Contributor III
862 Views

An alternative to consider is to write a post-processor program. If you have lots of text interspersed with the numbers, that can be difficult to do. On the other hand, if there are only numbers on some lines and only text on others, the post-processor would be very easy to implement.

0 Kudos
Reply