java.lang.StrictMath.signum(float f)方法實例
java.lang.StrictMath.signum(float f) 方法返回參數的正負號函數,如果參數爲0返回即零,如果參數大於零返回1.0f,如果參數小於零返回-1.0。它包括以下情況:
- 如果第一個參數爲NaN,則返回NaN。
- 如果參數爲正零或負零,那麼結果與參數一樣。
聲明
以下是**java.lang.StrictMath.signum()**方法的聲明
public static float signum(float f)
參數
- f --這是浮點值的正負號將被返回。
返回值
這個方法返回參數的符號函數。
異常
- NA
例子
下面的例子顯示java.lang.StrictMath.signum()方法的使用。
package com.yiibai; 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