我在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.
答案 0 :(得分:3)
查看eps
(https://de.mathworks.com/help/matlab/ref/eps.html),它会为您提供浮点相对精度,具体取决于您的系统架构。
请在此处进一步查看:https://de.mathworks.com/matlabcentral/answers/26458-machine-epsilon:
它大致意味着数字存储大约15-16位数 精确。如果一个数字大约为1,那么这意味着它可以 存储的错误大约为10 ^( - 16)
[...]
d = eps(X)是从abs(X)到下一个更大的正距离 与X"
相同精度的幅度浮点数这就是说d = eps(1)是最小的正值 (1 + d)是完全可表示的,与1不同。
1 + eps(1)是大于1的最小可表示数,单个 最低有效(最小变化)位的位差。
另外,请查看此处以了解更多有关它的信息(因为它不是特定于MATLAB的主题):https://en.wikipedia.org/wiki/Machine_epsilon