All integers that can be represented by floating point numbers have an exact representation. So you can safely use int
on the result. Inexact representations occur only if you are trying to represent a rational number with a denominator that is not a power of two.
That this works is not trivial at all! It’s a property of the IEEE floating point representation that int∘floor = ⌊⋅⌋ if the magnitude of the numbers in question is small enough, but different representations are possible where int(floor(2.3)) might be 1.
To quote from Wikipedia,
Any integer with absolute value less than or equal to 224 can be exactly represented in the single precision format, and any integer with absolute value less than or equal to 253 can be exactly represented in the double precision format.
Related Posts:
- Python division
- How can I use “e” (Euler’s number) and power operation in python 2.7
- How can I use “e” (Euler’s number) and power operation in python 2.7
- What does != do/mean in python
- Clamping floating numbers in Python?
- How to round a number to significant figures in Python
- How to perform bilinear interpolation in Python
- Inverse of Tan in python (tan-1)
- Inverse Cosine in Python
- Converting bytes to megabytes
- How do you round UP a number?
- How do you round UP a number?
- What is the difference between rw+ and r+
- Converting 3D polar coordinates to cartesian coordinates
- Converting integer to string in Python
- What is the C++ function to raise a number to a power?
- Unfamiliar symbol in algorithm: what does ∀ mean? [closed]
- Python Math – TypeError: ‘NoneType’ object is not subscriptable
- numpy max vs amax vs maximum
- What is the difference between range and xrange functions in Python 2.X?
- raw_input function in Python
- Integer division in Java [duplicate]
- Maximum and Minimum values for ints
- Maximum and Minimum values for ints
- What does the ^ (XOR) operator do? [duplicate]
- What do these operators mean (** , ^ , %, //)? [closed]
- What do these operators mean (** , ^ , %, //)? [closed]
- How do I parse a string to a float or int?
- Round a floating-point number down to the nearest integer?
- syntaxerror: “unexpected character after line continuation character in python” math
- syntaxerror: “unexpected character after line continuation character in python” math
- TypeError: ‘float’ object is not callable
- Calculating a 2D Vector’s Cross Product
- write() versus writelines() and concatenated strings
- Error: all the input array dimensions except for the concatenation axis must match exactly
- syntaxerror: “unexpected character after line continuation character in python” math
- No module named MySQLdb
- How do you express binary literals in Python?
- No module named MySQLdb
- Java Round up Any Number
- How do you use subprocess.check_output() in Python?
- How do order of operations go on Python?
- Maximum and Minimum values for ints
- JavaScript exponents
- How to perform an integer division, and separately get the remainder, in JavaScript?
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- How can I convert a character to a integer in Python, and viceversa?
- What does numpy.gradient do?
- How to perform an integer division, and separately get the remainder, in JavaScript?
- How can I concatenate str and int objects?
- How can I convert a character to a integer in Python, and viceversa?
- Python: OverflowError: math range error
- How can I use numpy.correlate to do autocorrelation?
- How can I convert radians to degrees with Python?
- Infinite integer in Python
- Lua replacement for the % operator
- How do you find the rightmost digit of an integer?
- How do you use subprocess.check_output() in Python?
- Overflow / math range error for log or exp
- How do I find the distance between two points?
- Converting binary to decimal integer output
- What is the fastest factorial function in JavaScript?
- How does Python manage int and long?
- How can I check for NaN values?
- Python – how to use the constant e^
- What does `<>` mean in Python?
- Checking whether a variable is an integer or not
- log2 in python math module
- What is the difference between ‘/’ and ‘//’ when used for division?
- How can I check for NaN values?
- Python – ‘ascii’ codec can’t decode byte
- How to return dictionary keys as a list in Python?
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- What is the most efficient way to calculate the least common multiple of two integers?
- What is the most efficient way to calculate the least common multiple of two integers?
- How can I convert a number from base 8 to base 10?
- What is the maximum number of edges in a directed graph with n nodes?
- Using multiple variables in a for loop in Python
- How to save decimal in java
- Probability of hash collision
- python math domain errors in math.log function
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- Is there a math nCr function in python?
- Round *UP* to the nearest 100 in SQL Server
- Display number with leading zeros
- How do I compute derivative using Numpy?
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- Converting integer to binary in python
- Convert floats to ints in Pandas?
- Is there a math nCr function in python? [duplicate]
- How to find length of digits in an integer?
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Rotating a Vector in 3D Space
- Using print() (the function version) in Python2.x
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- How to read a CSV file from a URL with Python?
- Mathematica matrix diagonalization
- Convert int to ASCII and back in Python
- How to import a csv-file into a data array?