Python floating point values are represented as double 64 bit values. The maximum value that any floating point number can take is approximately 1.8 x 10 308 . Any number greater than this will be indicated by the string inf
in Python.
|
Exit :
1.7e + 308 inf
Floating point numbers are represented in computer hardware as binary fractions. For example, the decimal fraction 0.125 has the value 1/10 + 2/100 + 5/1000, and similarly the binary fraction 0.001 has the value 0/2 + 0/4 + 1/8. These two fractions have the same meaning, the only real difference is that the first is written in fractional notation with base 10, and the second is — base 2.
Unfortunately, most decimal fractions cannot be represented exactly as binary fractions. A consequence of this is that, as a rule, the floating point decimal numbers entered are approximated only by the binary floating point numbers actually stored in the machine.
The float
type implements numbers .Real
is an abstract base class. Returns an expression that is converted to floating point. float
also has the following additional methods:
as_integer_ratio-python-reduced-fraction-given-rational/ rel = noopener target = _blank> float.as_integer_ratio (): returns a pair of integers whose ratio is exactly equal to the actual floating point value with a positive denominator. In the case of infinity, this causes an overflow error and value errors for Not a Number (NaNs).
|
Exit:
7/2
float.is_integer (): Returns True if the floating point instance is finite with an integer value, otherwise False.
|
Exit:
True False True
float.hex (): returns a hexadecimal string representation of a float.
|
Exit :
’0x1.1800000000000p + 5’
float.fromhex (s): returns a floating point number represented by the hex string s ... S lines can have leading and trailing spaces.
|
Output:
35.0
Note: float.hex () is an instance method, but float.fromhex () is a class method.