常用的算術方法
1.三角函式方法
| 方法 | 作用 |
|---|---|
| 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 toRadians(double a) | 角度轉化為弧度 |
| public static double toDegrees(double a) | 弧度轉化為角度 |
2.指數函式方法
| 方法 | 作用 |
|---|---|
| public static double exp(double a) | e的a次方 |
| public static double log(double a) | 取自然對數 |
| public static double log10(double a) | 取底數為10的對數 |
| public static double sqrt(double a) | 取a的平方根,a不為負值 |
| public static double cbrt(double a) | a的立方根 |
| public static double pow(double a,double b) | a的b次方 |
3.取整函式方法
| 方法 | 作用 |
|---|---|
| public static double ceil(double a) | 回傳大于等于引數的最小整數 |
| public static double floor(double a) | 回傳小于等于引數的最大整數 |
| public static double rint(double a) | 回傳與引數最接近的整數,如果兩個同為整數且同樣接近,結果取偶數 |
| public static double round(float a) | 將引數加上0.5后回傳與引數最近的整數 |
| public static long round(double a) | 將引數加上0.5后回傳與引數最近的整數并將其強制轉化為長整型 |
4.取最大值,最小值,絕對值
| 方法 | 作用 |
|---|---|
| public static double max(double a,double b) | 取a,b中的最大值 |
| public static double min(double a,double b) | 取a,b中的最小值 |
| abs(double a) | 回傳絕對值 |
上述double型可以變為其他型別如int,float.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/150182.html
標籤:其他
