我正在尝试在GWT中使用java.lang.Math.IEEEremainder(double f1, double f2)
。但我得到了以下异常。
[ERROR]第1119行:方法IEEEremainder(double,double)是 未定义类型Math
我尝试执行此代码:angle = Math.IEEEremainder(angle, 360.0);
如何在GWT中解决这个问题?如果它没有解决,那么实现Math.IEEEremainder
此方法的相同功能的替代方法是什么。
答案 0 :(得分:0)
根据JRE Emulation,GWT不支持此功能。
因此,如果你真的需要它并且不能解决它,你需要自己实现它。
如果我理解正确,你试图将角度限制在360度。 您可以使用以下代码实现此目的:
/**
* Normalize a degree value.
* @param d value
* @return 0<=value<=360
*/
public static double normalizeDegrees(double d)
{
while (d < 0)
{
d += 360;
}
while (d > 360)
{
d -= 360;
}
return d;
}
如果你得到正数,你甚至可以跳过上面的while
- 阻止。
答案 1 :(得分:0)
如果你真的需要在GWT中使用IEEEremainder方法,那就这样实现:
/**
* Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. The remainder value is
* mathematically equal to <code>f1 - f2</code> × <i>n</i>, where <i>n</i> is the
* mathematical integer closest to the exact mathematical value of the quotient {@code f1/f2}, and if two
* mathematical integers are equally close to {@code f1/f2}, then <i>n</i> is the integer that is even. If the
* remainder is zero, its sign is the same as the sign of the first argument. Special cases:
* <ul>
* <li>If either argument is NaN, or the first argument is infinite, or the second argument is positive zero or
* negative zero, then the result is NaN.
* <li>If the first argument is finite and the second argument is infinite, then the result is the same as the first
* argument.
* </ul>
* @param f1 the dividend.
* @param f2 the divisor.
* @return the remainder when {@code f1} is divided by {@code f2}.
*/
public static double IEEEremainder(double f1, double f2)
{
double div = Math.round(f1 / f2);
return f1 - (div * f2);
}
(我将此添加为新评论以显示语法突出显示)。