java math.cos 30_Java Math类

Java Math类

1 什么是Java Math类

Java Math类提供了几种用于数学计算的方法,例如min(),max(),avg(),sin(),cos(),tan(),round(),ceil(),floor(),abs()等

与StrictMath类的方法不同,Math类的等效函数的所有实现都不能定义为返回逐位相同的结果。这种使得在不需要严格的可重复性的情况下可以实现更好的性能。

如果大小为int或long,并且结果超出值的范围,则方法addExact(),subtractExact(),multipleExact()和toIntExact()会引发ArithmeticException异常。

2 Math类的例子1

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

public class Demo

{

public static void main(String[] args)

{

double x = 28;

double y = 4;

// return the maximum of two numbers

System.out.println("Maximum number of x and y is: " +Math.max(x, y));

// return the square root of y

System.out.println("Square root of y is: " + Math.sqrt(y));

//returns 28 power of 4 i.e. 28*28*28*28

System.out.println("Power of x and y is: " + Math.pow(x, y));

// return the logarithm of given value

System.out.println("Logarithm of x is: " + Math.log(x));

System.out.println("Logarithm of y is: " + Math.log(y));

// return the logarithm of given value when base is 10

System.out.println("log10 of x is: " + Math.log10(x));

System.out.println("log10 of y is: " + Math.log10(y));

// return the log of x + 1

System.out.println("log1p of x is: " +Math.log1p(x));

// return a power of 2

System.out.println("exp of a is: " +Math.exp(x));

// return (a power of 2)-1

System.out.println("expm1 of a is: " +Math.expm1(x));

}

}

输出结果为:

Maximum number of x and y is: 28.0

Square root of y is: 2.0

Power of x and y is: 614656.0

Logarithm of x is: 3.332204510175204

Logarithm of y is: 1.3862943611198906

log10 of x is: 1.4471580313422192

log10 of y is: 0.6020599913279624

log1p of x is: 3.367295829986474

exp of a is: 1.446257064291475E12

expm1 of a is: 1.446257064290475E12

3 Math类的例子2

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

public class Demo

{

public static void main(String[] args)

{

double a = 30;

// converting values to radian

double b = Math.toRadians(a);

// return the trigonometric sine of a

System.out.println("Sine value of a is: " +Math.sin(a));

// return the trigonometric cosine value of a

System.out.println("Cosine value of a is: " +Math.cos(a));

// return the trigonometric tangent value of a

System.out.println("Tangent value of a is: " +Math.tan(a));

// return the trigonometric arc sine of a

System.out.println("Sine value of a is: " +Math.asin(a));

// return the trigonometric arc cosine value of a

System.out.println("Cosine value of a is: " +Math.acos(a));

// return the trigonometric arc tangent value of a

System.out.println("Tangent value of a is: " +Math.atan(a));

// return the hyperbolic sine of a

System.out.println("Sine value of a is: " +Math.sinh(a));

// return the hyperbolic cosine value of a

System.out.println("Cosine value of a is: " +Math.cosh(a));

// return the hyperbolic tangent value of a

System.out.println("Tangent value of a is: " +Math.tanh(a));

}

}

输出结果为:

Sine value of a is: -0.9880316240928618

Cosine value of a is: 0.15425144988758405

Tangent value of a is: -6.405331196646276

Sine value of a is: NaN

Cosine value of a is: NaN

Tangent value of a is: 1.5374753309166493

Sine value of a is: 5.343237290762231E12

Cosine value of a is: 5.343237290762231E12

Tangent value of a is: 1.0

4 Java Math类的方法

java.lang.Math中类包含用于执行基本的数字操作,例如对数,立方根和三角函数等各种Java数学方法的各种方法,如下:

4.1 基本数学方法

方法

描述

它将返回给定值的绝对值。

它返回两个值中的最大值。

它用于返回两个值中的最小值。

用于将十进制数舍入到最接近的值。

它用于返回数字的平方根。

它用于返回数字的立方根。

它将第一个自变量的值返回到第二个自变量的幂。

它用于查找大于或等于自变量或数学整数的最小整数值。

用于查找第一个参数的绝对值以及第二个参数中指定的符号。

它用于返回第二个参数方向上与第一个参数相邻的浮点数。

它在正无穷大的方向上返回与d相邻的浮点值。

它在负无穷大的方向上返回与d相邻的浮点值。

它用于查找小于或等于自变量且等于双精度值的数学整数的最大整数值。

用于查找小于或等于商数的最大整数值。

它返回一个带正号的双精度值,大于或等于0.0且小于1.0。

它返回最接近给定参数且等于数学整数的double值。

它返回sqrt(x2 + y2),而没有中间的上溢或下溢。

它返回参数ulp的大小。

它用于计算IEEE 754标准规定的两个自变量的余数运算,并返回值。

它用于返回其参数的总和,如果结果溢出int或long,则抛出异常。

它返回参数的差,如果结果溢出一个int则抛出异常。

它用于返回参数的乘积,如果结果溢出int或long,则抛出异常。

它返回加一的参数,如果结果溢出一个int则抛出异常。

它用于返回减1的参数,如果结果溢出int或long,则抛出异常。

它用于返回参数的取反,如果结果溢出int或long,则抛出异常。

它返回long参数的值,如果该值溢出int则抛出异常。

4.2 对数数学方法

方法

描述

它返回双精度值的自然对数。

它用于返回双精度值的以10为底的对数。

它返回参数和1之和的自然对数。

它返回E升至双精度的幂,其中E是欧拉数,大约等于2.71828。

它用于计算E的幂并从中减去1。

4.3 三角数学方法

方法

描述

它用于返回给定双精度值的三角正弦值。

它用于返回给定double值的三角余弦值。

它用于返回给定double值的三角正切值。

它用于返回给定双精度值的三角正弦值。

它用于返回给定double值的三角Arc Cosine值。

它用于返回给定double值的三角Arc Tangent值。

4.4 双曲数学方法

方法

描述

它用于返回给定double值的三角双曲余弦值。

它用于返回给定double值的三角双曲正弦值。

它用于返回给定double值的三角双曲正切值。

4.5 角数学方法

方法

描述

用于将指定的弧度角转换为以度为单位的等效角。

用于将指定的度数角度转换为以弧度为单位的等效角度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值