简体   繁体   English

未为类型Math定义IEEEremainder(double,double)

[英]IEEEremainder(double, double) is undefined for the type Math

I am trying to use java.lang.Math.IEEEremainder(double f1, double f2) in GWT. 我试图在GWT中使用java.lang.Math.IEEEremainder(double f1, double f2) But I got below exception. 但我得到了例外。

[ERROR] Line 1119: The method IEEEremainder(double, double) is undefined for the type Math [错误] 1119行:未为类型Math定义方法IEEEremainder(double,double)

I attempted to execute this code : angle = Math.IEEEremainder(angle, 360.0); 我试图执行此代码: angle = Math.IEEEremainder(angle, 360.0);

How to solve this issue in GWT?. 如何在GWT中解决此问题? If its not solve then what would be the alternative way to achieve the same functionality of Math.IEEEremainder this method. 如果无法解决问题,那么实现此Math.IEEEremainder相同功能的Math.IEEEremainder方法是什么。

According to the JRE Emulation this function is not supported in GWT. 根据JRE仿真 ,GWT不支持此功能。

So if you really need it and can't work around it, you will need to implement it yourself. 因此,如果您确实需要它并且无法解决它,则需要自己实施。

If I understand it correctly, you are trying to limit the angle to 360 degrees. 如果我理解正确,则您尝试将角度限制为360度。 You could achieve that with this code: 您可以使用以下代码来实现:

/**
 * 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;
}

If you just got positive numbers, you can even skip the upper while -Block. 如果只是正数,您甚至可以while -Block时跳过上限。

If you really need to have the IEEEremainder method in GWT, implement it like that: 如果您确实需要在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&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<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);
}

(I added this as a new comment to show the syntax highlighting). (我将此添加为新注释以显示语法突出显示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM