Math函数

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // //求一个数字的n次方,是一个很大的需求
    // console.log(Math.pow(3,3))
    // console.log(Math.pow(30,30))

    // //es2016提出了新的方法求一个值的n次方,那就是 ** 操作符
    // console.log(3 ** 3)
    // console.log(30 ** 30)

    // //从右往左执行
    // console.log(3 ** 3 ** 2)
    // console.log(3 ** 9)

    // //书写二进制数字
    // let n1 = 0b00001111
    // console.log(n1)//15

    // //es6之前定义8进制的方式:0开头
    // let n2 = 017 //严格模式下报错
    // console.log(n2)
    // //es6之后定义8进制的方式0o开头     8进制(Octal)
    // let n3 = 0o17 //严格模式下也不会报错
    // console.log(n3)

    // //Math.trunc()去除小数部分
    // console.log(Math.floor(1.33)) //1
    // console.log(Math.ceil(1.33)) //2
    // console.log(Math.trunc(1.33)) //1

    // console.log(Math.floor(-1.33)) //-2
    // console.log(Math.ceil(-1.33))  //-1
    // console.log(Math.trunc(-1.33))  -1

    //Math.sign() 判断一个数字是正数还是负数还是0或者是NaN
    //如果是正数,返回1,负数返回-1,0返回0,NaN返回NaN

    // console.log(Math.sign(2.3)) //1
    // console.log(Math.sign(-1.3)) //-1
    // console.log(Math.sign(0)) //0
    // console.log(Math.sign(NaN)) //NaN
    // console.log(Math.sign(Infinity)) //1

    // // Math.sqrt()//平方根
    // // Math.cbrt()//立方根
    // console.log(Math.sqrt(9))
    // console.log(Math.cbrt(27))

    // Math.hypot()//求所有参数平方和的平方根
    // console.log(Math.hypot(4,9,16))//Math.sqrt(4*4 + 9*9 + 16*16)
    // //勾股定理 a的2次方 + b的2次方 = c的2次方
    // //已知直角三角形的两个直角边的长度为3,4求斜边的长度
    // console.log(Math.hypot(3,4))//5

  </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FGGIT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值