博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java. signum_Java Math类signum()及其方法示例
阅读量:2528 次
发布时间:2019-05-11

本文共 3617 字,大约阅读时间需要 12 分钟。

java. signum

数学类signum()方法 (Math class signum() method)

  • 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程序演示signum()方法的示例 (Java program to demonstrate example of signum() method)

// 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/

你可能感兴趣的文章
presumably用法
查看>>
stick用法
查看>>
TeamWork#3,Week5,The First Meeting of Our Team
查看>>
获取或者设置非行间样式方法二
查看>>
隔日随笔样式测试
查看>>
ICMP(网际控制报文协议)
查看>>
Sonar安装和常见问题解决
查看>>
[蓝桥杯]PREV-12.历届试题_危险系数
查看>>
redis常用命令
查看>>
第一周例行报告及作业汇总
查看>>
SQL2043N 与 linux的randomize_va_space特性
查看>>
树莓派使用无线网卡上网相关命令
查看>>
优秀架构师是怎么炼成的?
查看>>
Hibernate的CRUD
查看>>
StringBuilder和StringBuffer的区别
查看>>
基于Extjs+SpringMVC+MyBatis+Oracle的B/S信息系统简化开发思路
查看>>
【python】字典的嵌套
查看>>
微信运营:必须收藏的101条万能微信标题公式
查看>>
【XLL 框架库函数】 TempMissing/TempMissing12
查看>>
利用VS自带发布功能实现web项目快速部署
查看>>