Zero Integer Expressions

**|**** SimCon Home **
**|**** fpt Reference Manual Home ****|**

Why are Zero Integer Expressions a Problem?

In Fortran, the result of an integer division or exponentiation is integer. Engineers and scientists, who are simply translating a formula into code, may fail to see the implications. Expressions like 10**(-7) and (2/3) evaluate to zero.

Detecting Possible Problems

**fpt** checks the code for situations where zero integer expressions may cause a problem. The check is
always made and occurrences are marked by diagnostics. For example, the code shown below occurred in the
initialisation of the signal processing of a tracking radar. ixmt_c_tim is
the transmission time and trns_c_mid is the mid-frame time. The sub-expression
10**(-7) evaluates to zero so the mid-frame time is initialised to just after
midnight. Fortunately it all gets corrected on the first tracking frame.

num_c_trns(i) = 38 num_c_tot(i) = 38 half_c_n(i) = 15.5 ixmt_c_tim(i) = (sys_c_tim*(10**7))+150000 trns_c_mid(i) = (ixmt_c_tim(i)*(10**(-7)))+ & !--------------------------------------------------^--------------------------- !!! FPT - 3075 Integer raised to negative power - The result is usually zero !------------------------------------------------------------------------------ pri(i)*(num_c_trns(i)-half_c_n(i)) ENDDO

The example shown below occurred in a major climate analysis code. We are trying to find the surface area of a hailstone. We know the mass of the stone and the densisty of ice so we compute the volume. We get to the surface area by taking the cube root of the volume and then squaring the result, with a geometrical term which, outside the parentheses, reduces to PI. The problem here is that the sub-expression (2/3) evaluates to zero. Anything raised to the power zero is 1. All the hailstones have a surface area of PI square metres.

! HAIL krr = 0 kext_qh(i,k,j) = 0. DO kr = p_ff7i01,p_ff7i33 krr = krr+1 chem_new(i,k,j,kr) = ff5r(krr) geo_cs = 3.1415*(3*xh(krr)/(4*3.1415*0.9))**(2/3) !-----------------------------------------------------------------------^------ !!! FPT - 3077 Object raised to power which is result of an integer division !------------------------------------------------------------------------------ kext_qh(i,k,j) = kext_qh(i,k,j)+2.*geo_cs*(100.*col*3*xh(krr))*ff5r(krr) eff_ni(i,k,j) = SQRT(geo_cs/3.1415)**3*chem_new(i,k,j,kr)*xh(krr)+eff_ni(i,k,j) eff_di(i,k,j) = SQRT(geo_cs/3.1415)**2*chem_new(i,k,j,kr)*xh(krr)+eff_di(i,k,j) ENDDO ! ENDIF ENDDO

Copyright ©1995 to 2019 Software Validation Ltd. All rights reserved.