Floating Point Representation
The float type in Python represents the floating-point number. Float is used to represent real number and is written with a decimal point dividing the integer and fractional parts.
Example : 97.98,1.2789,31.2+e18, -21.54e50 all are floating point numbers.
Floating point representations vary from machine to machine. Python float values are represented as 64-bit double-precision values. The maximum value any floating-point number can be is approx 1.8*10^308.
Any number greater than this will be indicated by the string inf n Python.
Example :
print(1.7e308)
# greater than 1.8*10^308
# will print inf
print(1.82e308)
Output :
1.7e + 308
inf
Floating-point numbers are represented in computer hardware as base 2 (binary) functions.
Example :
The decimal fraction 0.125 has value 1/10 + 2/100 +5/1000, and in the same way the binary fraction 0.001 has value 0/2 + 0/4 + 0/8.
These are two fractions have identical values, the only real difference being that the first in written base 10 fractional notation and the second is base 2.
Note : In Python, float may also be written in scientific notation representing the power of 10.
For example : 2.5e2 represents the value 250.0 (2.5 * 10^2).
No comments:
Post a Comment