三角运算符所做的工作和您期料的一样。所有的角度需要指定为弧度而不是度。如果您愿意,您可以使用java math类的toRadians方法转化成弧度数。下面的查询用了math步骤计算了60度的正弦值,把它存在了名为x的变量里。
The trigonometric operators work as you would expect. All angles need to be specified as radians
and not degrees. You can do the conversion to radians yourself or use the Java Math.toRadians
helper method if you prefer. The query below uses the math step to calculate the sine of 60 degrees
and stores the result in a variable called "x".
我们可以用变量x来计算反正弦。
We can use our variable "x" to calculate the arcsine.
您可以把小精灵控制台当做一个计算器来验证我们得到了正确的答案。
We can use the Gremlin console as a calculator to prove that we got the correct answer back.
注意在使用Java Math库里,您需要注意可能的舍入错误。下面您希望返回的是1.0但实际上不是1,这是因为45度转化成弧度时数学库函数不够精确。注意,如果是使用Java Math类的toRadians方法,也不能达到理想的结果。
Note that just as when using the Java Math library you have to be aware of possible rounding
errors. You would expect the calculation below to return 1.0 but it does not as the conversion of 45
degrees to radians is not precise enough for the Math library. Note that using the Java
Math.toRadians method does not achieve the desired result either.
使用Java Math toRadians helper方法的一些实验。
Same experiment but using the helper method.
这个是使用math步骤另一个运算符的实验。我们可以使用ceil运算符来把我们的运算结果取整到最近的整数。
This presents us with a chance to experiment with another of the operators that the math step
provides. We can use the ceil operator to round our result up to the nearest integer.
浙公网安备 33010602011771号