7. Precision
Every FURY type comes in three real kinds, named by their bits:
| Kind | Units | Quantities | Systems | Real kind |
|---|---|---|---|---|
| 32 bits | uom32 | qreal32 | system_si32 | R4P |
| 64 bits | uom64 | qreal64 | system_si64 | R8P |
| 128 bits | uom128 | qreal128 | system_si128 | R16P |
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:
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 mThe 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.