Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
anonymous123
5,794 PointsFloating Point Arithmetic Issues and Limitations
Is it just me or does the python specification use fraction and decimal interchangeably.
When the python interpreter encounters a floating point number it creates a base 2 binary fraction for it that is an approximation of the encountered floating point number because most of the time decimal fractions cannot be represented exactly as binary fractions. The the decimal returned by the Python interpreter is an approximation of the binary fraction approximation. <-- This is correct right?
2 Answers
Steven Parker
243,199 PointsEvery numeric storage type has it's own precision and magnitude limitations, but there's no reason that decimal to binary conversion should not be exact as long as these limits are not being exceeded.
Note that even in decimal (base 10) representation, some fractions cannot be represented exactly. For example, ⅔ can be approximated as .66 or .6666 and so on, but it can never be represented exactly. Other fractions, like ½ are easily represented precisely in both base 10 and base 2. But any arbitrary fractional value is more likely to require approximation in base 2 than in base 10.
anonymous123
5,794 PointsSteven Parker https://docs.python.org/2/tutorial/floatingpoint.html <~ what I wrote is a summary of this doc so I’m confused
Steven Parker
243,199 PointsI think that doc uses the word "decimal" to refer to "base 10". I also expanded my answer a bit, hope that clears it up.