[英]Have I encountered a limit to mpmath's floating-point precision?
mpmath
purports to support "arbitrary-precision floating-point arithmetic." mpmath
声称支持“任意精度浮点算术”。
And yet . 但是 。 .
。 .
。
>>> import mpmath
>>> 1 + mpmath.erf(-5.921)
mpf('1.1102230246251565e-16')
>>> 1 + mpmath.erf(-5.922) # I expect a smaller positive number here.
mpf('0.0')
Am I missing something? 我想念什么吗? Or is this a fundamental limitation of
mpmath
? 还是这是
mpmath
的基本限制?
@jonrsharpe has suggested that the problem is that I've submitted a float
to erf
. @jonrsharpe建议问题在于我已向
erf
提交了一个float
。 However, the code below shows that this is not the problem: 但是,以下代码显示这不是问题:
>>> 1 + mpmath.erf(mpmath.mpf('-5.922'))
mpf('0.0')
The issue in this particular case has to do with mpmath
's global prec
ision setting being too low. 在这种特殊情况下的问题,有做
mpmath
的全球prec
ision设置过低。 The default value for prec
is prec
的默认值为
>>> mpmath.mp.prec
53
When I set it to 100
, I get the result I was expecting: 当我将其设置为
100
,我得到了预期的结果:
>>> 1 + mpmath.erf(-5.922)
mpf('5.5236667058718205581661131647751e-17')
In this case the speed difference isn't noticeable, but note that increasing the precision generally increases the time required to compute the result. 在这种情况下,速度差异并不明显,但是请注意,提高精度通常会增加计算结果所需的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.