Monday, June 18, 2018
Approximate fun
Newest addition to https://github.com/aroberge/experimental
> python -m experimental
experimental console version 0.9.6. [Python version: 3.6.1]
~~> from __experimental__ import approx
~~> 0.1 + 0.2
0.30000000000000004
~~> 0.1 + 0.2 == 0.3
False
~~> # Attempt to use approximate comparison with defining tolerances
~~> 0.1 + 0.2 ~= 0.3
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'rel_tol' is not defined
~~> rel_tol = abs_tol = 1e-8
~~> 0.1 + 0.2 ~= 0.3
True
~~> 2**0.5 ~= 1.414
False
~~> abs_tol = 0.001
~~> 2**0.5 ~= 1.414
True
No comments:
Post a Comment
Spammers: none shall pass.
Note: Only a member of this blog may post a comment.