Parameter Values when Emulating Real Arithmetic

The declaration of a Fortran parameter might be written, for example

REAL(KIND=4),PARAMETER :: c = 2.9979E+8

When the real objects are emulated, it is not sufficient simply to change the declaration to

TYPE (em_real_k4),PARAMETER :: c = 2.9979E+8

The problem is that the conversion of the real value 2.9979E+8 to an emulated 4-byte real number has been defined by a subroutine, but the compiler cannot call this subroutine at compile time. The value 2.9979E+8 must be explicitly converted to the emulated type. The re-engineered code must be written:

TYPE (em_real_k4),PARAMETER :: c = em_real_k4(2.9979E+8)

In the same way, the functions for arithmetic operators and intrinsic functions cannot be used to compute values at compile time. Therefore, for example, the statements in the original code:

REAL (KIND=kr4),PARAMETER :: pi = 3.141593 REAL (KIND=kr4),PARAMETER :: tpi = 2 * pi

must be converted to:

TYPE (em_real_k4),PARAMETER :: pi = em_real_k4(3.141593) TYPE (em_real_k4),PARAMETER :: tpi = em_real_k4( 2 * pi%value )

The parameter pi is now a derived type, and the value component must be specified, even though this is the only component in the type.