开源改变世界

解决浮动精度错误 #44

推推 grbl 3年前 (2023-02-09) 153次浏览
关闭
RasyidUFA 开启了这个问题 2018 年 12 月 26 日 · 2 条评论
关闭

解决浮动精度错误#44

RasyidUFA 开启了这个问题 2018 年 12 月 26 日 · 2 条评论

评论

解决浮动精度错误 #44

如我们所见,在源代码中,您使用简单的操作来比较两个浮点值

if ((posPause.X != posWorld.X)){
    // this sometimes won'twork.
}

由于两个值的精度不同,浮点数的比较可能不相等。

然后

我们可以用

// in some static class
public static double EPSILON= 1E-5; // 0.00001 Precision Point

// anywhere
if (Math.Abs(posPause.X - posWorld.X) > EPSILON){
    //This will always work
}
解决浮动精度错误 #44
所有者

这是一个好点,我会接管这个

解决浮动精度错误 #44 svenhb 添加了 增强 标签 2018 年 12 月 26 日
解决浮动精度错误 #44
所有者

在版本 1.2.3.x 中实现,感谢提示