SCJP须知:java.lang.Math
2004-09-10 15:47
645 查看
ceil(double)
返回不小于该参数的最小整数 (最接近负无穷)的 double 型值。
floor(double)
返回不大于该参数的最大整数 (最接近正无穷)的 double 型值。
IEEEremainder(double, double)
计算两个参数按照 IEEE 754 标准规定的求余运算。
pow(double, double)
返回参数一的参数二次方。
random()
返回 0.0 到 1.0 间的随机数。
rint(double)
返回与该参数最接近的整数。
double toDegrees(double angrad)
Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
double toRadians(double angdeg)
Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
Math 類別<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Math 類別的資料欄:
l Double E = 2.7182818284590452354
l Double PI = η
Math 類別的方法
l Abs(double x):傳回 x 的絕對值。X也可int long float
l acos(double x):傳回x值的反餘弦函數值。
l asin(double x):傳回x值的反正弦函數值。
l atan(double x):傳回x值的反正切函數值。
l atan2(double x, double y):傳回極座標(polar)的θ值
l ceil(double x):傳回不小於x的最小整數值。
l cos(double x):傳回x徑度的餘弦函數值
l exp(double x):傳回相當於ex值
l floor(double x):傳回不大於x的最大整數值
l log(double x):傳回x的自然對數函數值
l max(double x,double y):傳回x、y較大數
l min(double x,double y):傳回x、y較小數
l pow(double x,double y):傳回xy值
l random():傳回亂數值
l rint(double x):傳回最接近x的整數值
l round(double x):傳回x的四捨五入值
l sin(double x): 傳回x徑度的正弦函數值
l sqrt(double x): 傳回x開平方值
l tan(double x): 傳回x徑度的正切函數值
l toDegrees(double angrad):傳回將angrad徑度轉換成角度
l toRadians(double angdeg): 傳回將angdeg角度轉換成徑度
Field Summary | |
static double | E The doublevalue that is closer than any other to e, the base of the natural logarithms. |
static double | PI The doublevalue that is closer than any other to pi, the ratio of the circumference of a circle to its diameter. |
Method Summary | |
static double | abs(double a) Returns the absolute value of a doublevalue. |
static float | abs(float a) Returns the absolute value of a floatvalue. |
static int | abs(int a) Returns the absolute value of an intvalue. |
static long | abs(long a) Returns the absolute value of a longvalue. |
static double | acos(double a) Returns the arc cosine of an angle, in the range of 0.0 through pi. |
static double | asin(double a) Returns the arc sine of an angle, in the range of -pi/2 through pi/2. |
static double | atan(double a) Returns the arc tangent of an angle, in the range of -pi/2 through pi/2. |
static double | atan2(double y, double x) Converts rectangular coordinates ( x, y) to polar (r, theta). |
static double | ceil(double a) Returns the smallest (closest to negative infinity) doublevalue that is not less than the argument and is equal to a mathematical integer. |
static double | cos(double a) Returns the trigonometric cosine of an angle. |
static double | exp(double a) Returns Euler's number e raised to the power of a doublevalue. |
static double | floor(double a) Returns the largest (closest to positive infinity) doublevalue that is not greater than the argument and is equal to a mathematical integer. |
static double | IEEEremainder(double f1, double f2) Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. |
static double | log(double a) Returns the natural logarithm (base e) of a doublevalue. |
static double | max(double a, double b) Returns the greater of two doublevalues. |
static float | max(float a, float b) Returns the greater of two floatvalues. |
static int | max(int a, int b) Returns the greater of two intvalues. |
static long | max(long a, long b) Returns the greater of two longvalues. |
static double | min(double a, double b) Returns the smaller of two doublevalues. |
static float | min(float a, float b) Returns the smaller of two floatvalues. |
static int | min(int a, int b) Returns the smaller of two intvalues. |
static long | min(long a, long b) Returns the smaller of two longvalues. |
static double | pow(double a, double b) Returns the value of the first argument raised to the power of the second argument. |
static double | random() Returns a doublevalue with a positive sign, greater than or equal to 0.0and less than 1.0. |
static double | rint(double a) Returns the doublevalue that is closest in value to the argument and is equal to a mathematical integer. |
static long | round(double a) Returns the closest longto the argument. |
static int | round(float a) Returns the closest intto the argument. |
static double | sin(double a) Returns the trigonometric sine of an angle. |
static double | sqrt(double a) Returns the correctly rounded positive square root of a doublevalue. |
static double | tan(double a) Returns the trigonometric tangent of an angle. |
static double | toDegrees(double angrad) Converts an angle measured in radians to an approximately equivalent angle measured in degrees. |
static double | toRadians(double angdeg) Converts an angle measured in degrees to an approximately equivalent angle measured in radians. |
java.lang.Object | +----java.lang.Math
public final class Math
extends Object 类
Math包含基本数学操作如指数,对数,平方根和三角函数。
为确保 Java 程序的可移植性, 此软件包中对数学函数的定义必须与某些公开的算法结果一致。 这些算法可从著名的网络程序库
netlib中的软件包 "Freely Distributable Math Library" (
fdlibm)中得到。 这些用 C 语言写成的算法按照 Java 的浮点运算规则解释执行所有的浮点运算。
该网络程序库可在 World Wide Web 的下列站点查找
http://netlib.att.com/然后进行关键字搜索目标 "
fdlibm"。
该 Java 数学程序库的版本为
fdlibmdated January 4, 1995。
fdlibm对函数给出了多种定义 (如对
acos), 使用 "IEEE 754 core function" 版 (在以字母
e开头的文件中)。
变量索引
E该
double值非常接近
e, 自然对数的底数。
PI
该
double值非常接近 pi, 圆的周长与直径之比。
方法索引
abs(double)返回
double型值的绝对值。
abs(float)
返回
float型值的绝对值。
abs(int)
返回
int型值的绝对值。
abs(long)
返回
long型值的绝对值。
acos(double)
返回一个角的反余弦值,范围 0.0 到 pi。
asin(double)
返回一个角的反正弦值, 范围 -pi/2 到 pi/2 。
atan(double)
返回一个角的反正切值, 范围 -pi/2 到 pi/2 。
atan2(double, double)
将直角坐标 (
b,
a) 转换为极坐标 (r, theta)。
ceil(double)
返回不小于该参数的最小整数 (最接近负无穷)的
double型值。
cos(double)
返回一个角的余弦。
exp(double)
返回 e (即, 2.718...) 的
double次方。
floor(double)
返回不大于该参数的最大整数 (最接近正无穷)的
double型值。
IEEEremainder(double, double)
计算两个参数按照 IEEE 754 标准规定的求余运算。
log(double)
返回(以e为底)
double值的自然对数。
max(double, double)
返回两个
double型值中较大的一个。
max(float, float)
返回两个
float型值中较大的一个。
max(int, int)
返回两个
int型值中较大的一个。
max(long, long)
返回两个
long型值中较大的一个。
min(double, double)
返回两个
double型值中较小的一个。
min(float, float)
返回两个
float型值中较小的一个。
min(int, int)
返回两个
int型值中较小的一个。
min(long, long)
返回两个
long型值中较小的一个。
pow(double, double)
返回参数一的参数二次方。
random()
返回
0.0到
1.0间的随机数。
rint(double)
返回与该参数最接近的整数。
round(double)
返回与该参数最接近的
long型数。
round(float)
返回与该参数最接近的
int型数。
sin(double)
返回一个角的正弦。
sqrt(double)
返回
double型值的平方根。
tan(double)
返回一个角的正切。
变量
Epublic static final double E
该
double值非常接近于
e, 自然对数的底数。
PI
public static final double PI
该
double值非常接近 pi, 圆的周长与直径之比。
方法
sinpublic static native double sin(double a)
返回一个角的正弦值。
参数:
a - 以弧度计算的角度。
返回值:
参数的正弦值。 cos
public static native double cos(double a)
返回一个角的余弦值。
参数:
a - 以弧度计算的角度。
返回值:
参数的余弦值。 tan
public static native double tan(double a)
返回一个角的正切值。
参数:
a - 以弧度计算的角度。
返回值:
参数的正切值。 asin
public static native double asin(double a)
返回一个角的反正弦值, 范围 -pi/2 到 pi/2 。
参数:
a - 以弧度计算的角度。
返回值:
参数的反余弦值。 acos
public static native double acos(double a)
返回一个角的反余弦值,范围 0.0 到 pi。
参数:
a - 以弧度计算的角度。
返回值:
参数的反余弦值。 atan
public static native double atan(double a)
返回一个角的反正切值, 范围 -pi/2 到 pi/2 。
参数:
a - 以弧度计算的角度。
返回值:
参数的反正切值。 exp
public static native double exp(double a)
返回 e (即, 2.718...) 的 a 次方,
double型值。
参数:
a - 一个
double型值。
返回值:
ea, 这里 e 是自然对数的底数。 log
public static native double log(double a)
返回 a 的(以e为底)
double型的自然对数值。
参数:
a - 大于
0.0的数。
返回值:
ln
a,
a的自然对数。 sqrt
public static native double sqrt(double a)
返回 a 的平方根,
double型值。
参数:
a - 一个
double型值。
返回值:
a的平方根。若参数为 NaN 或小于零, 则结果为 NaN。 IEEEremainder
public static native double IEEEremainder(double f1, double f2)
计算两个参数按照 IEEE 754 标准规定的求余运算。 余数等于
f1 - f2× n, 这里 n 是最接近商
f1/f2的整数,并且如果有两个同样最接近于
f1/f2,则 n 取偶数的一个。 如果余数是零, 则它的符号与第一个参数相同。
参数:
f1 - 被除数。
f2 - 除数。
返回值:
f1被
f2除的余数。 ceil
public static native double ceil(double a)
返回不小于该参数的最小整数 (最接近负无穷)的
double型值。
参数:
a - 一个
double型值。
返回值:
返回不小于该参数的最小整数 (最接近负无穷)的
double型值。 floor
public static native double floor(double a)
返回不大于该参数的最大整数 (最接近正无穷)的
double型值。
参数:
a - 一个
double型值。
a - 指定值。
返回值:
返回不大于该参数的最大整数 (最接近正无穷)的
double型值。 rint
public static native double rint(double a)
返回与该参数最接近的整数。
参数:
a - 一个
double型值。
返回值:
最接近
a的整数的
double型值。 如果两个
double型值同样接近于该参数,返回值为偶数的那一个。 atan2
public static native double atan2(double a, double b)
将直角坐标 (
b,
a) 转换为极坐标 (r, theta)。 该方法计算
b/a的反正切得到相位 theta, 范围 -pi 到 pi。
参数:
a - 一个
double型值。
b - 一个
double型值。
返回值:
极坐标(r, theta)中的 theta 部分对应于 Cartesian 坐标中的点 (b, a)。 pow
public static native double pow(double a, double b)
返回以参数一为底数,参数二为指数的幂值。
若 (
a == 0.0),则
b必须大于
0.0; 否则将抛出一个异常。 如果 (
a <= 0.0) 且
b为整数,则发生异常。
参数:
a - 一个
double型值。
b - 一个
double型值。
返回值:
ab。
抛出: ArithmeticException
如果 (
a == 0.0) 且 (
b <= 0.0), 或如果 (
a <= 0.0) 且
b不为整数。 round
public static int round(float a)
返回与该参数最接近的
int型数。
如果该参数为负无穷或值小于等于
Integer.MIN_VALUE, 则结果等于
Integer.MIN_VALUE。
如果该参数为正无穷或值大于等于
Integer.MAX_VALUE, 则结果等于
Integer.MAX_VALUE。
参数:
a - 一个
float型值。
返回值:
该参数四舍五入到最近的
int型值。
参见:
MAX_VALUE, MIN_VALUE round
public static long round(double a)
返回与该参数最接近的
long型数。
如果该参数为负无穷或值小于等于
Long.MIN_VALUE, 则结果等于
Long.MIN_VALUE。
如果该参数为负无穷或值小于等于
Long.MAX_VALUE, 则结果等于
Long.MAX_VALUE。
参数:
a - 一个
double型值。
返回值:
该参数四舍五入到最近的
long型值。
参见:
MAX_VALUE, MIN_VALUE random
public static synchronized double random()
返回
0.0到
1.0间的随机数。 所谓的随机数发生器通常是伪随机数发生器,因为它产生的数会周期性循环。
返回值:
返回
0.0到
1.0间的伪随机数。
参见:
nextDouble abs
public static int abs(int a)
返回 a 的
int型的绝对值。 如果参数非负,返回该参数。如果参数为负,返回其相反数。
注意到如果该参数等于
Integer.MIN_VALUE, 可表示的最小负
int型值, 则结果与之相等且为负。
参数:
a - 一个
int型值.
返回值:
参数的绝对值。
参见:
MIN_VALUE abs
public static long abs(long a)
返回 a 的
long型的绝对值。 如果参数非负,返回该参数。如果参数为负,返回其相反数。
注意到如果该参数等于
Long.MIN_VALUE, 可表示的最小负
long型值, 则结果与之相等且为负。
参数:
a - 一个
long型值。
返回值:
参数的绝对值。
参见:
MIN_VALUE abs
public static float abs(float a)
返回 a 的
float型的绝对值。 如果参数非负,返回该参数。如果参数为负,返回其相反数。
参数:
a - 一个
float型值。
返回值:
参数的绝对值。 abs
public static double abs(double a)
返回 a 的
double型的绝对值。 如果参数非负,返回该参数。如果参数为负,返回其相反数。
参数:
a - 一个
double型值。
返回值:
参数的绝对值。 max
public static int max(int a, int b)
返回两个
int型值中较大的一个。
参数:
a - 一个
int型值.
b - 一个
int型值.
返回值:
a和
b中的较大者。 max
public static long max(long a, long b)
返回两个
long型值中较大的一个。
参数:
a - 一个
long型值。
a - 一个
long型值。
返回值:
a和
b中的较大者。 max
public static float max(float a, float b)
返回两个
float型值中较大的一个。 只要有一个是
NaN, 则结果是
NaN。 不象数字的比较运算符,此方法认为负零严格小于正零。
参数:
a - 一个
float型值。
b - 一个
float型值。
返回值:
a和
b中的较大者。 max
public static double max(double a, double b)
返回两个
double型值中较大的一个。 只要有一个是
NaN, 则结果是
NaN。 不象数字的比较运算符,此方法认为负零严格小于正零。
参数:
a - 一个
double型值。
b - 一个
double型值。
返回值:
a和
b中的较大者。 min
public static int min(int a, int b)
返回两个
int型值中较小的一个。
参数:
a - 一个
int型值.
b - 一个
int型值.
返回值:
a和
b中的较小者。 min
public static long min(long a, long b)
返回两个
long型值中较小的一个。
参数:
a - 一个
long型值。
a - 一个
long型值。
返回值:
a和
b中的较小者。 min
public static float min(float a, float b)
返回两个
float型值中较小的一个。 只要有一个是
NaN, 则结果是
NaN。 不象数字的比较运算符,此方法认为负零严格小于正零。
参数:
a - 一个
float型值。
b - 一个
float型值。
返回值:
a和
b中的较小者。 min
public static double min(double a, double b)
返回两个
double型值中较小的一个。 只要有一个是
NaN, 则结果是
NaN。 不象数字的比较运算符,此方法认为负零严格小于正零。
参数:
a - 一个
double型值。
b - 一个
double型值。
返回值:
a和
b中的较小者。
IEEEremainder toDegrees toRadians 有大写字母
相关文章推荐
- java.lang.Math中的基本方法
- 使用java.lang.Math 生成随机数字
- 一次泛型引起的意外:java.math.BigDecimal cannot be cast to java.lang.Integer
- java.math.BigInteger cannot be cast to java.lang.Long
- 类型转换错误java.math.BigDecimal cannot be cast to java.lang.String
- java.math.BigDecimal cannot be cast to java.lang.String
- java.math.BigDecimal cannot be cast to java.lang.String解决方法
- 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
- 可以自定义一个Java.lang.String/Math这样的类么?
- java.math.BigInteger cannot be cast to java.lang.Long
- java.math.BigInteger cannot be cast to java.lang.Long异常
- java.lang.ClassCastException: java.math.BigDecimal错误
- 关于 java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
- java.lang.Math
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
- 类型转换错误java.math.BigDecimal cannot be cast to java.lang.String
- 【问题解决:连接异常】 java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
- java.math.BigDecimal cannot be cast to java.lang.String问题解决方案