如何在gnuplot中使用floor函数

5
这里,OP使用gnuplot中的floor函数定义了round函数。对于floor的帮助文档如下所示:
gnuplot> help floor
 The `floor(x)` function returns the largest integer not greater than its
 argument.  For complex numbers, `floor` returns the largest integer not
 greater than the real part of its argument.

我该如何使用floor函数?我已经尝试了:
gnuplot> floor(7.3)
         ^
         invalid command

我能否以某种方式改变数字舍入的小数位数?


1
请再次阅读您链接的问题。作者将自己的 round 函数定义为 round(x) = x - floor(x) < 0.5 ? floor(x) : ceil(x)。要使用 gnuplot 进行测试,您必须执行例如 print floor(7) - Christoph
哦,我明白了,谢谢。我会修改关于“floor”使用的问题。 - Wakan Tanka
1个回答

7
要检查或打印函数调用的结果,您必须明确地使用print命令。
gnuplot> print floor(7.3)
7

要修改链接的round函数,只在某些小数位上进行舍入,请使用以下方法

round(x) = x - floor(x) < 0.5 ? floor(x) : ceil(x)
round2(x, n) = round(x*10**n)*10.0**(-n)

并且像这样调用它

gnuplot> print round2(7.3456, 1)
7.3
gnuplot> print round2(7.3456, 2)
7.35

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接