%uA0java.lang.StrictMath.signum(double d)%uA0方法返回参数的符号函数,如果参数为0返回零,如果参数大于零返回1.0,如果参数小于零返回-1.0。它包括以下情况:
- 如果第一个参数为NaN,则返回NaN。
- 如果参数为正零或负零,那么结果与参数一样。
声明
以下是java.lang.StrictMath.signum()方法的声明
public static double signum(double d)
参数
-
d%uA0-- 这是浮点值的正负号将被返回。
返回值
这个方法返回参数的符号函数。
异常
-
NA
例子
下面的例子显示java.lang.StrictMath.signum()方法的使用。
package com.yiibai import java.lang.* public class StrictMathDemo { public static void main(String[] args) { double d1 = 102.20d, d2 = 0.0d, d3 = -0.0d // returns 1.0 if the argument is greater than zero double retval = StrictMath.signum(d1) System.out.println("Value = " + retval) /* if the argument is positive zero, then the result is the same as the argument */ retval = StrictMath.signum(d2) System.out.println("Value = " + retval) /* if the argument is negative zero, then the result is the same as the argument */ retval = StrictMath.signum(d3) System.out.println("Value = " + retval) } }
让我们来编译和运行上面的程序,这将产生以下结果:
Value = 1.0 Value = 0.0 Value = -0.0