Add tag on float imprecision#1395
Merged
Merged
Conversation
Adds a tag on float imprecision
Contributor
|
Can we also give an example where there are represented exactly: # This is because 0.125 is precisely 1/8, or 1/(2^3)
>>> format(0.125, '.25f')
'0.1250000000000000000000000'Then the >>> x = 0.1 + 0.1 + 0.1
>>> y = 0.3
>>> x == y
False
>>> from math import isclose
>>> x = 0.0000001
>>> y = 0.0000002
>>>
>>> a = 123456789.01
>>> b = 123456789.02
>>>
>>> print('x = y:', isclose(x, y, abs_tol=0.0001, rel_tol=0.01))
x = y: True
>>> print('a = b:', isclose(a, b, abs_tol=0.0001, rel_tol=0.01))
a = b: True
>>> And last not to use # As you can see, since we passed an approximate binary float to the Decimal constructor it did it's best to represent that binary float exactly!!
# So, instead, use strings or tuples in the Decimal constructor.
>>> from decimal import Decimal
>>> format(0.1, '.25f')
'0.1000000000000000055511151'
>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625') |
Contributor
Author
|
The tag is already fairly long, and our aim is to try and keep them fairly short so i've only put in what I think is most important, and linked to other things. Regarding your three points:
|
Contributor
Alright, You can do that for the 2nd point, maybe add a single line example? |
Contributor
Author
Shivansh-007
approved these changes
Feb 3, 2021
Contributor
Shivansh-007
left a comment
There was a problem hiding this comment.
Thanks! Looks Good To Me!
Xithrius
approved these changes
Feb 3, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds a tag on float imprecision
