Skip to content

7. Precision ​

Every FURY type comes in three real kinds, named by their bits:

KindUnitsQuantitiesSystemsReal kind
32 bitsuom32qreal32system_si32R4P
64 bitsuom64qreal64system_si64R8P
128 bitsuom128qreal128system_si128R16P
f90
metre32  = uom32('m [length]')
metre64  = uom64('m [length]')
metre128 = uom128('m [length]')
third32  = qreal32(1._R4P / 3._R4P, metre32)
third64  = qreal64(1._R8P / 3._R8P, metre64)
third128 = qreal128(1._R16P / 3._R16P, metre128)
print '(A)', third32%stringify()
print '(A)', third64%stringify()
print '(A)', third128%stringify()

Quantities of different kinds can be summed, subtracted, multiplied, divided and compared; as for the intrinsic reals, the result has the kind of the more precise operand. A quantity is assigned to one of another kind, with the conversion of its magnitude:

f90
sum128 = third128 + third64
narrowed = third128
print '(A)', sum128%stringify()
print '(A)', narrowed%stringify()
$ tutorial_7
+0.333333343E+00 m
+0.33333333333333331E+000 m
+0.333333333333333333333333333333333317E+0000 m
+0.666666666666666648162949589580724262E+0000 m
+0.33333333333333331E+000 m

The sum is computed in 128 bits, but its 64 bits operand carries only 16 significant digits: mixing kinds does not add precision.

Without quadruple precision ​

The 128 bits kinds need a compiler with quadruple precision reals, and FURY and PENF compiled with -DPENF_R16P. Without the macro the 128 bits types do not exist, rather than being double precision in disguise: a program that uses qreal128 does not compile. The Precision page has the details.

What you learned

The 32, 64 and 128 bits types, mixed-kind arithmetic and assignment, the optional quadruple precision. Reference: Precision.

Next: 8. Non-linear conversions.

Released under GPL v3, BSD 2-Clause, BSD 3-Clause or MIT, at your choice.