Overview¶
The library contains two core types: rpe_var
and rpe_shadow
.
Both of these types are subclasses of the abstract type rpe_type
.
These types can be used in place of real-valued variables to perform calculations with floating-point numbers represented with a reducednumber of bits in the floating-point significand.
Basic use of the reduced-precision types¶
The rpe_var
type is a simple container for a double precision floating point value, whereas the rpe_shadow type acts as a memory-view onto an existing double precision floating point number defined outside the type itself.
Changing the value of an rpe_shadow
variable also changes the value of the floating point number it is shadowing and vice-versa, since they both refer to the same block of memory.
Using an rpe_var
instance is as simple as declaring it and using it just as you would a real number:
TYPE(rpe_var) :: myvar
myvar = 12
myvar = myvar * 1.287 ! reduced-precision result is stored in `myvar`
An rpe_shadow
instance is different, it must first be initialized to point at an existing real-valued variable before it can be used:
REAL(KIND=RPE_REAL_KIND) :: real_target
TYPE(rpe_shadow) :: myvar
CALL init_shadow (myvar, target)
myvar = 12 ! both `myvar` and `real_target` contain the value 12
myvar = myvar * 1.287 ! reduced precision result is stored in both `myvar` and `real_target`
Controlling the precision¶
The precision used by reduced precision types can be controlled at two different levels.
Each reduced precision variable has an sbits
attribute which controls the number of explicit bits in its significand.
This can be set independently for different variables, and comes into effect after it is explicitly set.
TYPE(rpe_var) :: myvar1
TYPE(rpe_var) :: myvar2
! Use 16 explicit bits in the significand of myvar1, but only 12 in the
! significand of myvar2.
myvar1%sbits = 16
myvar2%sbits = 12
For variables whose sbits
attribute has not been explicitly set, there is a default global precision level, set by RPE_DEFAULT_SBITS
.
This will stand-in for the number of explicit significand bits in any variable where sbits
has not been set.
Setting RPE_DEFAULT_SBITS
once to define the global default precision, and setting the precision of variables that require other precision manually using the sbits
attribute is generally a good strategy.
However, if you change RPE_DEFAULT_SBITS
during execution, the document Changing RPE_DEFAULT_SBITS during execution lists some details you should be aware of.
The emulator can also be turned off completely by setting the module variable RPE_ACTIVE
to .FALSE.
.