数学函数
常量函数
Math.E; //e,2.718
Math.LN2;//ln2 0.693
Math.LN10; //ln10 2.302
Math.LOG2E //以2为底e的对数 1.414
Math.LOG10E;// 以10为底e的对数 0.434
Math.PI;// 3.14159
Math.SQRT1_2;// 根号下二分之一 0.707
Math.SQRT2;// 根2 1.414
角度转弧度 30°*(π/180)=0.523320rad
弧度转角度 0.523320rad*(180/π)=30°
数学方法
Math.abs(x);//求绝对值
Math.round(3.56);//4 四舍五入
Math.ceil(3.56);//4向上舍入
Math.floor(3.56);// 3 向下舍入
Math.random()//随机0-1
function randoms(min,max){
return Math.floor(Math.random()*(max-min)+min);
}
Math.max(3,5,7);//7 最大值
Math.min(3,5,7);//3 最小值
Math.sqrt(2);//根2 ===Math.SQRT2
Math.pow(3,2);//3的2次方
Math.pow(2,6);// 1<<6
Math.pow(8,1/3);//三次根号下8 sqrt效率更高
数组最值 var arr=[1,3,5,7,9,10];
var max=Math.max.apply(null,arr);
var min=Math.min.apply(null,arr);
常用数学函数总结
最新推荐文章于 2022-01-28 22:44:22 发布