# Understanding Precision in Matlab

10 views (last 30 days)
Commented: Walter Roberson on 1 Jul 2020
I have a simple question. How to split the different between the two numbers into 1e6 increment (unisg linspace)?
The numbers: 5.047639467288342e+4 and 5.047639467288343e+4.
Thanks

Stephen Cobeldick on 1 Jul 2020
"How to split the different between the two numbers into 1e6 increment (unisg linspace)?"
You can't. There are no binary floating point numbers inbetween the two values that you gave.
We can confirm this very easily by noting that their hex representations differ only by 1:
>> A = 5.047639467288342e+4;
>> B = 5.047639467288343e+4;
>> num2hex(A)
ans = 40e8a58ca12906dd
>> num2hex(B)
ans = 40e8a58ca12906de
Thank you! Then, I have to consider changing the algorithm then.

Walter Roberson on 1 Jul 2020
You cannot do that with double precision.
If you have the symbolic toolbox then:
r = linspace(sym('5.047639467288342e+4'), sym('5.047639467288343e+4'), 1e6+1);
Note that the results will be symbolic numbers with higher precision than double(), so if you were to double() them, it would be with loss of precision