(all numbers discussed are in decimal)

lets say we have a floating point data type that is like :

m * 10 ^ e

where m is the mantissa . and max mantissa size is 1 ( 0 <= m <= 9);

e is the exponent and its size is  -1 <= e <= 1

we say our data type Max value is 90 and its Min value is 0

BUT : that does not mean we can represent all numbers that are in this limit . we can only represent 27 numbers ( 9 * 3 ) excluding zero.

specifically we can't represent 89 in this way since it has a two digit mantissa (and non of them are zero).

so technically analogous to the above descriptions . in a float data type (in any programming language) there must be some integers between Max and Min values that we cannot store in a float data type .

is the above argument sound . if it is please give an example how to show this in java or c ?


Yes, this is correct. For one thing, there are numbers that cannot be represented with a finite length. One of the most notable is $1/10$. In a binary representation, this is the repeating, non-terminating decimal $0.0\overline{0011}$.

Also, for a given precision (Let's say $24$, since that is that precision of 32-bit IEEE-$754$ floating point numbers, like the float type of Java or C), there are that many binary significant digits, which means that as the numbers get larger, the space between them increases as well. With $24$ significant digits in binary, the space between consecutive numbers is $2^{e-24}$, where $e$ is the exponent factor. A signed $32$-bit number can be as large as $2^{31}=2147483648$. At this point, the number is $2^{31-24}=2^8=128$ away from the previous number. That means anything between $2147483520$ and $2147483648$ cannot be accurately represented by a float, and will be rounded to one of those values.

  • $\begingroup$ also the smallest number that cannot be demonstrated is $2^{24}+1$ since its binary is $1000000000000000000000001$ which has one bit more than 24 bits and the extra bit cannot be expressed in the exponent $\endgroup$ – kiyarash Feb 1 '15 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.