数字类
1、三角函数方法
static double sin(double a ) : 返回角的三角正弦
static double cos(double a) : 返回角的三角余弦
static double tan(double a) : 返回角的三角正切
static double asin(double a) : 返回角的反正弦
static double acos(double a) : 返回角的反余弦
static double atan(double a) : 返回角的反正切
static double toRadians(double a) : 将角转换为弧度
static doueble toDegrees(double a) : 将弧度转化为角
2、指数函数方法
static double exp(double a) : 用于获取e的a次方;
static double log(double a) : 即lna;
static double log10(double a) : 即log10a;
static double sqrt(double a ):用于取a的平方根;
static double cbrt(double a) : 用于取a的立方根;
static double pow(double a, double b) : 用于求a的b次方;
3、取整函数方法
static double ceil(double a):返回大于等于a的整数值,返回值类型为double;
static double floor(double a) : 返回小于等于a的整数值,返回值类型为double;
static double rint(double a) : 返回与a最接近的整数值,返回值类型为double;(如果两个同为整数且同样接近,选取偶数值的那个)
static int random( ):返回带正号的 double 值,该值大于等于 0.0 且小于 1.0。
static int round(double a ): 其值等于Math.floor(a + 0.5),返回值类型为long;
static long round(float a ): 其值等于Math.floor(a + 0.5),返回值类型为int;
4、取最大值、最小值、绝对值函数方法
public static double max(double a,doubleb):取a与b之间的最大值。
public static int min(int a,intb):取a与b之间的最小值,参数为整型。
public static long min(long a,longb):取a与b之间的最小值,参数为长整型。
public static float min(float a,floatb):取a与b之间的最小值, 参数为浮点型。
public static double min(double a,doubleb):取a与b之间的最小值,参数为双精度型。
public static int abs(int a):返回整型参数的绝对值。
public static long abs(long a):返回长整型参数的绝对值。
public static float abs(float a):返回浮点型参数的绝对值。
public static double abs(double a);:返回双精度型参数的绝对值。
5、BigInteger运算方法
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[] divideAndRemainder(BigInteger val):用数组返回余数和商,结果数组中第一个值为商,第二个值为余数。
public BigIteger pow(int exponen):进行取参数的exponent次方操作。
public Biglnteger negateO:取相反数。
public BigInteger shifLeft(intn):将数字左移n位,如果n为负数,做右移操作。
public BigInteger shiftRight(intn):将数字右移n位,如果n为负数,做左移操作。
public BigInteger and(BigInteger val):做与操作。
public BigInteger or(BigInteger val):做或操作。
public int compareTo(BigInteger val):做数字比较操作。
public boolean equals(Object x);当参数x是BigInteger类型的数字并且数值相等时,返回true.public BigInteger min(BigInteger val):返回较小的数值。
public BigInteger max(BigInteger val):返回较大的数值。
6、在BigDecimal类中常用的两个构造方法如下:
public BigDecimal(double val):实例化时将双精度型转换为BigDecimal类型。
public BigDecimal(String val):实例化时 将字符串形式转换为BigDecimal类型。
BigDecimal类型的数字可以用来做超大浮点数的运算,如加、减、乘、除等。在所有的运算中,除法是最复杂的,因为在除不尽的情况下末位小数点的处理是需要考虑的。
下面列举了BigDecimal 类中实现加、减、乘、除的方法:
public BigDecimal add(BigDecimal augend):做加法操作。
public BigDecimal subtract(BigDecimal subtrahend):做减法操作。
public BigDecimal multiply(BigDecimal multiplicand):做乘法操作。
public BigDecimal divide(BigDecimal divisor,int scale,int roundingMode):做除法操作,方法中3个参数分别代表除数、商的小数点后的位数、近似处理模式。