我有一些关于 MatLab 中 num2str() fctn 精度的问题。
a=0.11111111111111;
b=a;
Linux/OSX: num2str(a+b,25): ans=0.2222222222222221655465116
Windows: num2str(a+b,25): ans= 0.222222222222222
谁能解释一下使用 Linux/OSX 系统时小数点后 15 位之后的数字是从哪里来的? num2str() 可以获得的最大精度是多少?
num2str 文档中有一些我不完全理解的提示。
Note: If you specify precision to exceed the precision of the input floating-point data type, the results might not match the input values to the precision you specified. The result depends on your computer hardware and operating system.
最佳答案
看看 eps
( https://de.mathworks.com/help/matlab/ref/eps.html ),它为您提供浮点相对精度,这取决于您的系统架构。
进一步查看此处:https://de.mathworks.com/matlabcentral/answers/26458-machine-epsilon :
It roughly means that numbers are stored with about 15-16 digits of precision. If a number is approximately 1, then that means it can be stored with an error of around 10^(-16)
[...]
d = eps(X) is the positive distance from abs(X) to the next larger in magnitude floating point number of the same precision as X"
That says that d = eps(1) is the smallest positive value such that (1+d) is exactly representable and is different than 1.
1+eps(1) is the smallest representable number greater than 1, a single bit difference in the least significant (smallest change) bit.
也可以看看这里,了解更多关于它的一般信息(因为它并不是真正的 MATLAB 特定主题):https://en.wikipedia.org/wiki/Machine_epsilon
关于matlab - matlab 精度 num2string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37073697/