一个简单的浮点加法 x+y in 精度为 4(即 IEEE 尾数宽度 3),其中 3 位用于 的指数(emax=3
, emin=-4
)x = mpfr('0.75')
,但在应该为 时却y = mpfr('0.03125')
错误地给出了结果。请注意,对于这种降低精度的格式,这是一个次正规数。mpfr('0.75')
mpfr('0.8125')
0.3125
编辑:从链接中提取的终端交互并包括在内以供将来参考。
>>> "{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)
>>>