A simple floating-point addition x+y in with precision 4 (i.e. IEEE mantissa width 3), with 3 bits for exponent (emax=3
, emin=-4
) for x = mpfr('0.75')
, y = mpfr('0.03125')
incorrectly gives mpfr('0.75')
as result when it should be mpfr('0.8125')
. Note that 0.3125
is a subnormal number for this reduced precision format.
Edit: Terminal interaction extracted from link and included for future reference.
>>> "{0:.10Df}".format(mpfr('0.75')+mpfr('0.03125'))
'0.7500000000'
>>> get_context()
context(precision=4, real_prec=Default, imag_prec=Default,
round=RoundToNearest, real_round=Default, imag_round=Default,
emax=3, emin=-4,
subnormalize=True,
trap_underflow=False, underflow=False,
trap_overflow=False, overflow=False,
trap_inexact=False, inexact=True,
trap_invalid=False, invalid=False,
trap_erange=False, erange=False,
trap_divzero=False, divzero=False,
trap_expbound=False,
allow_complex=False)
>>>