在 Gnuplot forces "No usable data in this plot to auto-scale axis range" 中添加条件绘图

Addition in conditional plotting in Gnuplot forces "No usable data in this plot to auto-scale axis range"

我使用简单的代码根据条件从一个文件创建一系列图像。在这样做的过程中,我意识到:

splot [1:150][1:150][] "dinozaur" u 5:6:((==0.4+0.0025*3)?:1/0)

...不起作用但是:

splot [1:150][1:150][] "dinozaur" u 5:6:((==0.40750)?:1/0)

...有效。

然而,

splot [1:150][1:150][] "dinozaur" u 5:6:((==0.5+0.0025*3)?:1/0)

...和

splot [1:150][1:150][] "dinozaur" u 5:6:((==0.50750)?:1/0)

工作。

如果我遇到错误,那就是标题中的错误。 我在做什么明显的错误吗?

我附上了一段数据文件,其中第 4 列的值为 0.40750 https://www.dropbox.com/s/lpv0m2wfoo3qwl7/dinozaur?dl=0

计算机上的浮点运算并不精确。例如,0.4+0.0025*3 可能与 0.40750 不完全相同。有关详细信息,请查看此问题:Is floating point math broken?

您通常希望避免测试浮点数的严格相等性。相反,您可以测试两个数字是否足够接近。例如,

eps = 1E-10
splot [1:150][1:150][] "dinozaur" u 5:6:((abs( - (0.4+0.0025*3)) < eps) ?  : 1/0)

应该可以。