美文网首页
math函数

math函数

作者: Jey | 来源:发表于2018-04-26 10:31 被阅读7次
    1. math.abs() 绝对值
    2. math.random() 返回介于 0 ~ 1 之间的一个随机数,取m-n之间的随机数:Math.random()*(n-m)+m。
    3. Math.ceil() 求一个最接近它的整数,它的值大于或等于这个浮点数
      例如:
    Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=12
    Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-11
    
    1. Math.floor() 求一个最接近它的整数,它的值小于或等于这个浮点数
      例如:
    Math.floor(11.46)=Math.floor(11.68)=Math.floor(11.5)=11
    Math.floor(-11.46)=Math.floor(-11.68)=Math.floor(-11.5)=-12
    
    1. Math.round() 表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,例如:Math.round(11.5)的结果是12,Math.round(-11.5)的结果为-11.
      Math.round( )符合这样的规律:小数点后大于5正数和负数全部加1,等于5正数加1,小于5正数和负数全不加1。
    小数点后第一位<5
    正数:Math.round(11.46)=11
    负数:Math.round(-11.46)=-11
     
    小数点后第一位>5
    正数:Math.round(11.68)=12
    负数:Math.round(-11.68)=-12
     
    小数点后第一位=5
    正数:Math.round(11.5)=12
    负数:Math.round(-11.5)=-11
    总结:(小数点后第一位)大于五全部加,等于五正数加,小于五全不加。
    
    1. Math.max(x...) 返回大的
    2. Math.min(x...) 返回小的
    3. Math.pow(x,y) 返回 x 的 y 次幂的值。Math.pow(2,3)值是8
    4. Math.sqrt(x) 参数 x 的平方根,也叫向量归一化,在3D中常用到。Math.sqrt(9)是3
    5. math.huge 返回HUGE_VAL的值,是一个大于任何数字的值。
    6. Math.sin(x) 参数 x 的正弦值。返回值在 -1.0 到 1.0 之间。x参数:必需。一个以弧度表示的角。将角度乘以 0.017453293 (2PI/360)即可转换为弧度。

    相关文章

      网友评论

          本文标题:math函数

          本文链接:https://www.haomeiwen.com/subject/jkgckftx.html