js基本功——Math
目录:
- 对数运算是幂运算的逆运算,如果a>0且1不等于1,则a的x次方=N,x即为以a为底N的对数,及x=logaN
- 以10为底的对数常用lg表示
- 以常数e为底的对数用ln表示
- 弧度 = 角度 * Math.PI / 180;
- 角度 = 弧度 * 180 / Math.PI
- E
- LN2
- LN10
- LOG2E
- LOG10E
- PI
- SQRT2
- SQRT1_2
- abs(x)
- ceil(x)
- floor(x)
- max(x,y)
- min(x,y)
- pow(x,y) x的y次幂
- ceil(x) 上取整
- floor(x) 下取整
- random() 返回0-1之间的随机数
- round(x) 四舍五入取整
- sin(arc)
- asin(num)
- cos(arc)
- acos(num)
- tan(arc)
- atan(num)
- atan2(y,x) 返回从x轴到点(x,y)的角度的弧度值
- exp(x) e的x次幂
- log(x) x的自然对数,即以e为底x的对数
- sqrt(x) x的平方根
1 var m = Math; 2 w = function(str){document.write(str+"<br>");} 3 arc = function(deg){return deg * m.PI / 180;} 4 deg = function(arc){return arc * 180 / m.PI;} 5 w("Math.E = "+m.E); 6 w("Math.LN2 = "+m.LN2); 7 w("Math.LN10 = "+m.LN10); 8 w("Math.LOG2E = "+m.LOG2E); 9 w("Math.PI = "+m.PI); 10 w("Math.SQRT1_2 = "+m.SQRT1_2); 11 w("Math.SQRT2 = "+m.SQRT2); 12 w("Math.abs(-1) = "+m.abs(-1)); 13 w("Math.sin(arc(30)) = "+m.sin(arc(30))); 14 w("Math.asin(0.49999999999999994) = "+m.asin(0.49999999999999994)); 15 w("Math.cos(arc(60)) = "+m.cos(arc(60))); 16 w("Math.tan(arc(45)) = "+m.tan(arc(45))); 17 w("Math.atan(1) = "+m.atan(1)); 18 w("Math.floor(1.2) = "+m.floor(1.2)); 19 w("Math.ceil(1.2) = "+m.ceil(1.2)); 20 w("Math.atan2(1,1) = "+m.atan2(1,1)); 21 w("arc(45) = "+arc(45));

浙公网安备 33010602011771号