gnuplot:sgn(NaN) 应该是什么?
gnuplot: what should sgn(NaN) be?
我偶然发现了以下内容:
如果你输入
print sgn(NaN)
结果将是 0
。
gnuplot 帮助说:
The sgn(x) function returns 1 if its argument is positive, -1 if its argument is negative, and 0 if its argument is 0. If the argument is a complex value, the imaginary component is ignored.
然而,NaN
不是正数,不是负数,也不是0。
我会预料到结果 NaN
。
有人可以对此发表评论并解释一下吗?
正如@Ethan 评论的那样,如果可能没有一个通用标准,可能每个人都根据自己的需要来定义它。
好吧,那我只需要定义自己的 sgn(x) 函数即可。
这让我想到了如何与 NaN
进行比较,请参阅
代码:
mysgn(x) = x==x ? sgn(x) : NaN
print mysgn(999)
print mysgn(0)
print mysgn(-999)
print mysgn(NaN)
结果:
1
0
-1
NaN
我偶然发现了以下内容:
如果你输入
print sgn(NaN)
结果将是 0
。
gnuplot 帮助说:
The sgn(x) function returns 1 if its argument is positive, -1 if its argument is negative, and 0 if its argument is 0. If the argument is a complex value, the imaginary component is ignored.
然而,NaN
不是正数,不是负数,也不是0。
我会预料到结果 NaN
。
有人可以对此发表评论并解释一下吗?
正如@Ethan 评论的那样,如果可能没有一个通用标准,可能每个人都根据自己的需要来定义它。 好吧,那我只需要定义自己的 sgn(x) 函数即可。
这让我想到了如何与 NaN
进行比较,请参阅
代码:
mysgn(x) = x==x ? sgn(x) : NaN
print mysgn(999)
print mysgn(0)
print mysgn(-999)
print mysgn(NaN)
结果:
1
0
-1
NaN