For large quotients,
floor division (//) doesn’t seem to be necessarily equal to the floor of regular division
Input : 269792703866060742 // 3 Output : 89930901288686914 Input : math.floor(269792703866060742 / 3) Output : 89930901288686912
In the above examples, the output for
floor division(//) is 89930901288686914 and the output for math.floor is 89930901288686912. All the digits are equal to each other except the last two digits in this example i.e 14 and 12.
The reason the quotients in the example is not equal is, in the
math.floor(a/b) case the result is calculated with floating-point arithmetic (IEEE-754 64-bit), which means there is a maximum precision. The quotient obtained is larger than the
2^53 limit above which floating-point is no longer accurate up to the unit. However, with the
floor division(//) Python uses its unlimited integer range, and so that result is correct.
Note: For int and long arguments, true division (/) may lose information; this is in the nature of true division (as long as rationals are not in the language). Algorithms that consciously use longs should consider using //, as true division (/) of longs retains no more than 53 bits of precision (on most platforms).
On a typical computer system, a ‘double precision’ (64-bit) binary floating-point number has a coefficient of 53 bits, an exponent of 11 bits, and one sign bit. Refer IEEE 754.
Equal Output Not Equal Output
- Benefits of Double Division Operator over Single Division Operator in Python
- Python | K Division Grouping
- Tuple Division in Python
- Division Operators in Python
- Python - Dictionary Values Division
- Python List Equality | Program to check if two given matrices are identical
- Python - Check whether a string starts and ends with the same character or not (using Regular Expression)
- Regular Expression in Python with Examples | Set 1
- Extracting email addresses using regular expressions in Python
- Find all the numbers in a string using regular expression in Python
- Regular Expressions in Python | Set 2 (Search, Match and Find All)
- What is the maximum possible value of an integer in Python ?
- Python | sympy.Integer() method
- Convert string to integer in Python
- Python | Convert Tuple to integer
- Python | Binary list to integer
- Python - String Integer Product
- Convert integer to string in Python
- Python - Maximum of Sting Integer list
- Python program to concatenate two Integer values into one
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.