本文共 3617 字,大约阅读时间需要 12 分钟。
java. signum
signum() method is available in java.lang package.
signum()方法在java.lang包中可用。
signum() method is used to return the sign function of the given float argument type method. It is an odd mathematical function to extract the sign of the real number.
signum()方法用于返回给定float参数类型方法的sign函数。 提取实数的符号是一个奇数数学函数。
signum() method is static a method, it is accessible with the class name too.
signum()方法是静态方法,也可以使用类名进行访问。
signum() method method does not throw any exception.
signum()方法 method不会引发任何异常。
Syntax:
句法:
public static float signum(float value); public static double signum(double value);
Parameter(s):
参数:
value – represents the float/double floating-point value.
value –表示浮点/双浮点值。
Return value:
返回值:
The return type of this method is float/double, – it returns the sign function of the given argument.
此方法的返回类型为float / double ,它返回给定参数的符号函数。
Note:
注意:
If we pass "NaN", it returns the same value i.e. ("NaN").
如果我们传递“ NaN”,它将返回相同的值,即(“ NaN”)。
If we pass zero (0 or -0), it returns the same value with the same sign.
如果我们传递零(0或-0),它将返回具有相同符号的相同值。
If we pass the value less than 0, it returns the -1.0.
如果传递的值小于0,则返回-1.0。
If we pass the value greater than 0, it returns the 1.0.
如果传递的值大于0,则返回1.0。
// Java program to demonstrate the example of // signum(float fl) method of Math Classpublic class SignumMethod { public static void main(String[] args) { // Declaring the variables float f1 = -0.0f; float f2 = 0.0f; float f3 = -0.6f; float f4 = 2.0f; // Here , we will get (-0.0) because we are passing // parameters whose value is (-0.0f) System.out.println("Math.signum(f1): " + Math.signum(f1)); // Here , we will get (0.0) and we are passing // parameters whose value is (0.0f) System.out.println("Math.signum(f2): " + Math.signum(f2)); // Here , we will get (-1.0) and we are passing // parameters whose value is (-0.6f) System.out.println("Math.signum(f3): " + Math.signum(f3)); // Here , we will get (1.0) and we are passing // parameters whose value is (2.0f) System.out.println("Math.signum(f4): " + Math.signum(f4)); }}
Output
输出量
E:\Programs>javac SignumMethod.javaE:\Programs>java SignumMethodMath.signum(f1): -0.0Math.signum(f2): 0.0Math.signum(f3): -1.0Math.signum(f4): 1.0
Example 2:
范例2:
// Java program to demonstrate the example of // signum(double do) method of Math Classpublic class SignumMethod { public static void main(String[] args) { // Declaring the variables double d1 = -0.0f; double d2 = 0.0f; double d3 = -0.6f; double d4 = 2.0f; // Here , we will get (-0.0) because we are passing // parameters whose value is (-0.0f) System.out.println("Math.signum(d1): " + Math.signum(d1)); // Here , we will get (0.0) and we are passing // parameters whose value is (0.0f) System.out.println("Math.signum(d2): " + Math.signum(d2)); // Here , we will get (-1.0) and we are passing // parameters whose value is (-0.6f) System.out.println("Math.signum(d3): " + Math.signum(d3)); // Here , we will get (1.0) and we are passing // parameters whose value is (2.0f) System.out.println("Math.signum(d4): " + Math.signum(d4)); }}
Output
输出量
E:\Programs>javac SignumMethod.javaE:\Programs>java SignumMethodMath.signum(f1): -0.0Math.signum(f2): 0.0Math.signum(f3): -1.0Math.signum(f4): 1.0
翻译自:
java. signum
转载地址:http://civzd.baihongyu.com/