Math

Java 的 Math 包含了用于执行基本数学运算的属性和方法,如初等指数、对数、平方根和三角函数。

Math 的方法都被定义为 static 形式,通过 Math 类可以在主函数中直接调用。

常量:

public static final double E = 2.7182818284590452354;
public static final double PI = 3.14159265358979323846;

常用方法:

// 三角函数相关
public static double sin(double a) {}
public static double cos(double a) {}
public static double tan(double a) {}
public static double asin(double a) {}
public static double acos(double a) {}
public static double atan(double a) {}
public static double atan2(double y, double x) {} // 将笛卡尔坐标转换为极坐标
public static double toRadians(double angdeg) {} // 将角度转换为弧度
public static double toDegrees(double angrad) {} // 将参数转化为角度
// 数学
public static double exp(double a) {} // e的次方
public static double log(double a) {} // 对数
public static double log10(double a) {} // 以10为底的对数
public static double sqrt(double a) {} // 开平方
public static double cbrt(double a) {} // 开立方
public static double IEEEremainder(double f1, double f2) {} // 余数
public static double ceil(double a) {} // 取上整
public static double floor(double a) {} // 取下整
public static double pow(double a, double b) {} // 次方
public static double rint(double a) {} // 返回与参数最接近的整数
// 绝对值
public static int abs(int a) {}
public static long abs(long a) {}
public static float abs(float a) {}
public static double abs(double a) {}
// 四舍五入
public static int round(float a) {}
public static long round(double a) {}
// 随机数
public static double random() {}
// 最大值
public static int max(int a, int b) {}
public static long max(long a, long b) {}
public static float max(float a, float b) {}
public static double max(double a, double b) {}
// 最小值
public static int min(int a, int b) {}
public static long min(long a, long b) {}
public static float min(float a, float b) {}
public static double min(double a, double b) {}
// 运算
public static int addExact(int x, int y) {} // 加法
public static long addExact(long x, long y) {} // 加法
public static int subtractExact(int x, int y) {} // 减法
public static long subtractExact(long x, long y) {} // 减法
public static int multiplyExact(int x, int y) {} // 乘法
public static long multiplyExact(long x, long y) {} // 乘法
public static int floorDiv(int x, int y) {} // 除法
public static long floorDiv(long x, long y) {} // 除法
public static int incrementExact(int a) {} // +1
public static long incrementExact(long a) {} // +1
public static int decrementExact(int a) {} // -1
public static long decrementExact(long a) {} // -1
public static int negateExact(int a) {} // 相反数
public static long negateExact(long a) {} // 相反数
public static int floorMod(int x, int y) {} // 取模
public static long floorMod(long x, long y) {} // 取模
public static int toIntExact(long value) {} // 转换为int

MIT Licensed | Copyright © 2018-present 滇ICP备16006294号

Design by Quanzaiyu | Power by VuePress