static float signum(float f)
描述 (Description)
java.lang.StrictMath.signum(float f)方法返回参数的signum函数,如果参数为零,则返回0;如果参数大于零,则返回1.0f,如果参数小于零,则返回-1.0f .It包括这些案件 -
- 如果第一个参数是NaN,则返回NaN。 。
- 如果参数为正零或负零,则结果与参数相同。
声明 (Declaration)
以下是java.lang.StrictMath.signum()方法的声明
public static float signum(float f)
参数 (Parameters)
f - 这是要返回其signum的浮点值。
返回值 (Return Value)
此方法返回参数的signum函数。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.StrictMath.signum()方法的用法。
package com.iowiki;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
float f1 = 102.20f, f2 = 0.0f, f3 = -0.0f;
// returns 1.0 if the argument is greater than zero
float retval = StrictMath.signum(f1);
System.out.println("Value = " + retval);
/* if the argument is positive zero, then the result is the
same as the argument */
retval = StrictMath.signum(f2);
System.out.println("Value = " + retval);
/* if the argument is negative zero, then the result is the
same as the argument */
retval = StrictMath.signum(f3);
System.out.println("Value = " + retval);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Value = 1.0
Value = 0.0
Value = -0.0