Overloading The Multiplication of Two Emulated Real Numbers

The Fortran function used to overload the * operator for the multiplication of two emulated 4-byte real numbers is shown below. Note that the function is elemental, which indicates that it can operate on whole arrays. The precision of the result is controlled by the function experiment_4 which is called to modify the result. experiment_4 is also called for both of the input arguments because either may be a Fortran parameter, or may be read from an input file, and may contain a number with a precision greater than the precision chosen in the experiment.

The code for the overload is written in an include file included in the Fortran module module_emulate_real_arithmetic. It is shown below.

ELEMENTAL FUNCTION multiply_em_real_k4_em_real_k4(a1mr4,a2mr4) TYPE (em_real_k4) :: multiply_em_real_k4_em_real_k4 TYPE (em_real_k4),INTENT(IN) :: a1mr4 TYPE (em_real_k4),INTENT(IN) :: a2mr4 TYPE (em_real_k4) :: t1mr4 TYPE (em_real_k4) :: t2mr4 t1mr4 = experiment_4(a1mr4) t2mr4 = experiment_4(a2mr4) multiply_em_real_k4_em_real_k4%value = t1mr4%value*t2mr4%value multiply_em_real_k4_em_real_k4 = experiment_4(multiply_em_real_k4_em_real_k4) END FUNCTION multiply_em_real_k4_em_real_k4