how many significant figures matlab uses?

24 views (last 30 days)
Osama Alkurdi
Osama Alkurdi on 1 Nov 2020
Edited: Bruno Luong on 1 Nov 2020
i read that matlab uses 16 significant figures, but look at the picture below it show that matlab uses 16 significant figures, and then uses 17 significant figures, can anyone explain to me how many significant figures that matlab uses during the calculation and how many significant figures matlab stores in the memory, please dont give me links.
i am very confused can any one explain this topic to me simply because i need it for my college project.

Accepted Answer

Bruno Luong
Bruno Luong on 1 Nov 2020
Edited: Bruno Luong on 1 Nov 2020
MATLAB does not work directly on digit. MATLAB uses IEEE 754 BINARY storage which is 52-bit (relative) precision.
Which is
>> 2^-52
ans =
>> eps(1)
ans =
It's somewhere between 15 and 16 digits.
The digit displayed on screen is just for human who use to digital numbers. It occur when user inquires the value on computer screen.
When display all screen you might see 16 or 17 digits by default in format long, but keep in mind it might be only an approximate of the binary coding.
And you can display even more. The numbers do not mean anything terribly meaningful after 16 digits. It just gives the exact digital conversion (up-to the last non-zero digit) of 52-bit of 2-radix coding
>> fprintf('%1.100f\n',pi)
>> fprintf('%1.100f\n',1/3)
Whereas those trailing digits marked by xxxx matter, it's your appreciation. People throw them away because it's smaller than the quantification error. But the approximated value of 1/3 under MATLAB is actually
(Note that any finite bit number in base 2 must be finite in base 10 since 2|10)
Bruno Luong
Bruno Luong on 1 Nov 2020
What does "get the rounding right to the final bit" exactly means?
I claim that for any double (x) in [0.5,1) this code always returns FALSE
num2digit=@(x)sprintf('%0.16f', x);
and this always returns TRUE
num2digit=@(x)sprintf('%0.16f', x);
However if one consider to relax x bracket in [0.1,0.5) one need 17 digits to replicate x
x = 11/5/5
num2digit= @(x,n)reshape(sprintf(['%0.' num2str(n) 'f'], x),[],length(x))';
c16=num2digit(x,16) % '0.4400000000000001'
c17=num2digit(x,17) % '0.44000000000000006'
str2double(c16)==x % false
str2double(c17)==x % true
This is no surprise since
>> eps(x)
ans =
So the last significant bit of x (=0.44000000000000006) is at 17 (fractional) digits

Sign in to comment.

More Answers (0)





Community Treasure Hunt

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

Start Hunting!