java之Math

Posted yxysuanfa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java之Math相关的知识,希望对你有一定的参考价值。

一、Math类
java.lang.Math提供了一系列静态方法用于科学计算;其方法的參数和返回值类型一般为double型。
abs     绝对值
acos,asin,atan,cos,sin,tan  三角函数
sqrt     平方根
pow(double a,doble b)     a的b次幂
log    自然对数
exp    e为底指数
max(double a,double b)
min(double a,double b)
random()      返回0.0到1.0的随机数
long round(double a)     double型数据a转换为long型(四舍五入)
toDegrees(double angrad)     弧度—>角度
toRadians(double angdeg)     角度—>弧度

二、BigInteger类
Integer类作为int的包装类,能存储的最大整型值为2^31-1,BigInteger类的数值范围较Integer类的数字
范围要大得多,能够支持随意精度的整数。


①构造器
BigInteger(String val)
经常用法
public BigInteger abs()
public BigInteger add(BigInteger val)
public BigInteger subtract(BigInteger val)
public BigInteger multiply(BigInteger val)
public BigInteger divide(BigInteger val)
public BigInteger remainder(BigInteger val)
public BigInteger pow(int exponent)
public BigInteger[] divdeAndRemainder(BigInteger val)

三、BigDecimal类
一般的Float类和Double类能够用来做科学计算或project计算。但在商业计算中,要求数字精度比較高,故用到java.math.BigDecimal类。BigDecimal类支持不论什么精度的定点数。


构造器
public BigDecimal(double val)
public BigDecimal(String val)
经常用法
public BigDecimal add(BigDecimal augend)
public BigDecimal subtract(BigDecimal subtrahend)
public BigDecimal multiply(BigDecimal multiplicand)
public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode)





































以上是关于java之Math的主要内容,如果未能解决你的问题,请参考以下文章

Java全栈JavaSE:17.基础API与常见算法

java -- MathBigIntegerBigDecimal类和基本类型的包装类正则表达式

猜数字游戏,判断输入的数字与系统产生的数字是否一致(Math.random()与if嵌套循环)

Java学习笔记之:java引用数据类型之字符串

Java之Java7新特性之try资源句式

java基础之java程序基础之字符和字符串