MATLAB Smallest Integer in floating point number system

I am interested in finding the smallest integer in MATLAB, say y, that is not representable in 64 bit floating point format so that the floating point number is not equal to y i.e., fl(y) is not y.
My insticts tells me that could be the underflow level given as 2^-1022 and its corresponding floating point number is 1.00...2^{-1022}
I don't whether this is correct. Help me find the number please.

 Accepted Answer

IEEE double has a 52-bit mantissa, plus there is a hidden bit, so effectively 53-bit mantissa. So you can exactly represent all integers up to 53 binary bits in IEEE double exactly. So 53 1's would be the largest integer with all 1's. Add one to that and you get a 54-bit integer that is a 1 followed by 53 0's, which because of the trailing 0's is also exactly representable in IEEE double (i.e., the last 0 is not representable, but because it is a 0 it doesn't affect the value). Add one more to that and you get a 54-bit integer that is a 1 followed by 52 0's followed by a 1. This is not representable exactly in IEEE double because of the 53-bit mantissa limitation. So the smallest integer number that cannot be represented exactly in IEEE double is the 54-bit binary integer 100...001, which is decimal
2^53+1
E.g.,
>> num2strexact(2^53,'fixed')
ans =
'9007199254740992'
>> num2strexact(2^53+1,'fixed')
ans =
'9007199254740992' <-- IEEE Double can't handle that extra 1
>> uint64(2^53)
ans =
uint64
9007199254740992
>> uint64(2^53)+1
ans =
uint64
9007199254740993 <-- uint64 has full 64 bits available for value
>> dec2bin(2^53)
ans =
'100000000000000000000000000000000000000000000000000000'
>> dec2bin(uint64(2^53)+1)
ans =
'100000000000000000000000000000000000000000000000000001'
Another clue is to use eps( ) to find the value of the least significant bit:
>> eps(2^53)
ans =
2
Since this value is greater than 1, that tells you that we are beyond the precision of IEEE Double to handle neighboring integers exactly.

4 Comments

@James TursaEdit: Using k=dec2bin(9.007199254740992e+15) produces '100000000000000000000000000000000000000000000000000000'.
size(k)=54
Could this be the correct floating number representation?
Is there any better way than dec2bin to compute the binary of 1+2^53?
format long g
x = flintmax('double');
fprintf('%ld\n', x)
9007199254740992
fprintf('%ld\n', x+1)
9007199254740992
y = 9007199254740993
y =
9.00719925474099e+15
fprintf('%ld\n', y)
9007199254740992
so flintmax('double')+1 is the smallest (positive) integer not exactly representable in IEEE double precision
@Walter Roberson Isn't it the same value as @James Tursa?
Your question is about how to find the integer. flintmax() is specifically designed as returning exactly that integer. So the answer is to call flintmax()
As to why that particular integer: see Jame's explanation. I might perhaps have written things slightly differently, but same conclusion.
If this is a homework question, then they are expecting that you will keep taking powers of 2 until you find one where 2^x + 1 - 2^x == 0
Is there any better way than dec2bin to compute the binary of 1+2^53?
"better" is not well defined, especially since 1+2^53 and dec2bin() of that character vector will not in fact return the number, since both of them operate in double precision and the point of the exercise is that the number you seek is not representable in double precision. You need to work in int64 or uint64

Sign in to comment.

More Answers (1)

You are indeed correct:
realmin,log2(realmin)
ans = 2.2251e-308
ans = -1022
Unless you actually mean integer, in which case the smallest integer is 0.
If you mean the lowest number of an IEEE double: that would be
-realmax
ans = -1.7977e+308

8 Comments

What could be the floating point number?
Do you mean what the binary representation would be?
Yes. The question says the integer that is NOT REPRESENTABLE, but isn't realmin representable?
If it isn't representable that means you can't write it.
This is the binary for the smallest number you can write with a double:
b=dec2bin(typecast(realmin,'uint64'),64);
fprintf('S E F\n%s %s %s\n',b(1),b(2:12),b(13:end))
S E F 0 00000000001 0000000000000000000000000000000000000000000000000000
If you want anything smaller you will need to use a quad or vpa. Anything between 0 and realmin can't be written as a double.
So is this the binary for realmin?
Yes. I typecast it to a 64 bit integer and converted that to a 64 digit binary number. I added two spaces and a header to explain what the numbers are.
@Rik It seems i'm getting a lil bit confuse. What is the difference between realmin value and the number 1+2^53 ? I guess your derivation was based on realmin right?
Anything between 0 and realmin can't be written as a double.
Incorrect. realmin is the smallest normalized positive value, but there are smaller subnormal positive values.
x = realmin
x = 2.2251e-308
y = eps(0)
y = 4.9000e-324
y < x
ans = logical
1

Sign in to comment.

Categories

Products

Release

R2020b

Asked:

on 26 Jan 2021

Edited:

on 27 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!