一、java中math类常用方法整理:
1、Math.sqrt()//计算平方根 例:Log.d("TAG","Math.sqrt(16)----:"+Math.sqrt(16));//4.0
2、Math.cbrt()//计算立方根 例: Log.d("TAG","Math.cbrt(8)----:"+Math.cbrt(8));//2.0
3、Math.hypot(x,y)//计算 (x的平方+y的平方)的平方根 例:Log.d("TAG","Math.hypot(3,4)----:"+Math.hypot(3,4));//5.0
4、Math.pow(a,b)//计算a的b次方 例: Log.d("TAG","Math.pow(3,2)----:"+Math.pow(3,2));//9.0
5、Math.exp(x)//计算e^x的值 例: Log.d("TAG","Math.exp(3)----:"+Math.exp(3));//20.085536923187668
6、Math.max();//计算最大值 例: Log.d("TAG","Math.max(2.3,4.5)----:"+Math.max(7,15));//15
7、Math.min();//计算最小值 例:Log.d("TAG","Math.min(2.3,4.5)----:"+Math.min(2.3,4.5));//2.3
8、Math.abs求绝对值 例: Log.d("TAG","Math.abs(-10.4)----:"+Math.abs(-10.4));//10.4
9、 Math.ceil向上取整 例: Log.d("TAG","Math.ceil(-10.1)----:"+Math.ceil(-10.1));//-10.0
10、Math.floor向下取整 例:Log.d("TAG","Math.floor(-10.1)----:"+Math.floor(-10.1));//-11.0
11、Math.random 取得一个大于或者等于0.0小于不等于1.0的随机数[0,1)
12、Math.rint /Math.round 四舍五入
13、Math.nextUp(a) 返回比a大一点点的浮点数
14、Math.nextDown(a) 返回比a小一点点的浮点数
15、Math.nextAfter(a,b) 返回(a,b)或(b,a)间与a相邻的浮点数 b可以比a小
二、js中math类常用方法整理:
abs(x) | 返回数的绝对值。 |
acos(x) | 返回数的反余弦值。 |
asin(x) | 返回数的反正弦值。 |
atan(x) | 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。 |
atan2(y,x) | 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。 |
ceil(x) | 对数进行上舍入。 |
cos(x) | 返回数的余弦。 |
exp(x) | 返回 e 的指数。 |
floor(x) | 对数进行下舍入。 |
log(x) | 返回数的自然对数(底为e)。 |
max(x,y) | 返回 x 和 y 中的最高值。 |
min(x,y) | 返回 x 和 y 中的最低值。 |
pow(x,y) | 返回 x 的 y 次幂。 |
random() | 返回 0 ~ 1 之间的随机数。 |
round(x) | 把数四舍五入为最接近的整数。 |
sin(x) | 返回数的正弦。 |
sqrt(x) | 返回数的平方根。 |
tan(x) | 返回角的正切。 |
toSource() | 返回该对象的源代码。 |
valueOf() | 返回 Math 对象的原始值。 |