精度 num2string matlab

precision num2string matlab

我有一些关于 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