Math对象没有构造函数,是一个固有的对象,这是它与Date,String对象的区别
Math的相关函数全部为静态函数,应该直接调用
Math三角函数与属性
Math.sin() -- 返回数字的正弦值
Math.cos() -- 返回数字的余弦值
Math.tan() -- 返回数字的正切值
Math.asin() -- 返回数字的反正弦值
Math.acos() -- 返回数字的反余弦值
Math.atan() -- 返回数字的反正切值
Math.atan2() -- 返回由x轴到点(x,y)的角度(以弧度为单位)
Math.PI 属性 -- 返回圆的周长与其直径的比值(圆周率π),约等于3.1415926
Math四舍五入类函数
Math.abs() -- 返回数字的绝对值
Math.ceil() -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入
Math.floor() -- 返回小于等于数字参数的最大整数,对数字进行下舍入
Math.round() -- 返回数字最接近的整数,四舍五入
Math随机数函数
Math.random() -- 返回0和1之间的伪随机数
Math最大最小类函数
Math.max() -- 返回数个数字中较大的值
Math.min() -- 返回数个数字中较小的值
Math.max()
max函数参数
- a,b,...,x,y -- 为number类型的数字,此值必须大于0
max函数返回值
返回数个数值中较大的值
如果max函数没有给出任何参数,返回-Infinity
如果有NaN或者非数字类型的参数,返回NaN
max函数示例
document.write(Math.max(5,8,6,-5,-6));//8
document.write(Math.max());//-Infinity
document.write(Math.max("dreamdu",8)); //NaN
document.write(Math.max(NaN,0)); //NaN
document.write(Math.max("-32","-9","-56","-878","-789","-767"));//-9
document.write(Math.max(-32,-9,-56,-878,-789,-767));//-9
document.write(Math.max("-32","-9",-56,"-878","-789",-767));//-9
document.write(Math.max(32,9,56,878,789,767));//878