<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js MathModule</title>
</head>
<body>
<script>
/*参考:https://www.w3school.com.cn/js/jsref_obj_math.asp
* 知识点:
* 1.*/
// 0.Math
console.log("Math:", Math);
// 1.向下取整。
console.log(Math.floor(4.6)); // 4
// 2.向上取整。
console.log(Math.ceil(2.38)); // 3
console.log(Math.ceil(2.38 * 10) / 10); // 2.4
// // 2.四舍五入。
// console.log(Math.round(4.6)); // 5
// // 3.返回较大值。
// console.log(Math.max(2, 3)); // 3
// // 4.返回较小值。
// console.log(Math.min(2, 3)); // 2
// // 5.返回数的绝对值。
// console.log("abs:", Math.abs(-3)); // abs: 3
//
// // 6.[0, 1)之间的随机数。
// console.log("\n6.");
// console.log(Math.random()); // [0, 1)
// // 打印介于[0,20)之间的随机整数。
// let randomNumbers = [];
// for (let i = 0; i < 200; i++) {
// randomNumbers.push(Math.floor(Math.random() * 20));
// }
// console.log("randomNumbers:", randomNumbers);
//
// // 7.Math.PI
// console.log("\n7.");
// console.log("\nMath.PI:", Math.PI);
// // Math.PI: 3.141592653589793
//
// // 8.Math.cos(x),其中x的单位是弧度。验证参考余弦曲线。
// console.log("\n8.");
// console.log(Math.cos(Math.PI)); // -1
// console.log(Math.cos(0)); // 1
// console.log(Math.cos(Math.PI / 2)); // 6.123233995736766e-17 约等于 0
//
// // 9.Math.sin(x),其中x的单位是弧度。验证参考正弦曲线。
// // 小数点后的15位是有效数字,第16位及以后为无效数字。
// console.log("\n9.");
// console.log("Math.sin(0):", Math.sin(0)); // 0
// console.log("Math.sin(Math.PI):", Math.sin(Math.PI)); // 1.2246467991473532e-16
//
// // 10.Math.asin(x) -> 一个数的反正弦值。
// // x,必需。必须是一个数值,该值介于 [-1.0, 1.0] 之间。
// // 返回的值是 [-PI/2, PI/2] 之间的弧度值。
// // 如果参数 x 超过了 -1.0 ~ 1.0 的范围,那么浏览器将返回 NaN。
// // 如果参数 x 取值 1,那么将返回 PI/2。
// console.log("\n10.");
// console.log("Math.asin(0):", Math.asin(0));
// console.log("Math.asin(-1):", Math.asin(-1));
// console.log("Math.asin(1):", Math.asin(1));
// console.log(Math.PI / 2);
// console.log(Math.asin(2));
// // Math.asin(0): 0
// // Math.asin(-1): -1.5707963267948966
// // Math.asin(1): 1.5707963267948966
// // 1.5707963267948966
// // NaN
//
// // 11.Math.pow(x,y) -> x 的 y 次幂
// // x,必需。底数。必须是数字。
// // y,必需。幂数。必须是数字。
// // 如果结果是虚数,则该方法将返回 NaN。
// // 如果由于指数过大而引起浮点溢出,则该方法将返回 Infinity。
// console.log("\n11.");
// console.log(Math.pow(0, 0)); // 1
// console.log(Math.pow(0, 1)); // 0
// console.log(Math.pow(1, 1)); // 1
// console.log(Math.pow(2, 3)); // 8
// console.log(Math.pow(-2, 3)); // -8
// console.log(Math.pow(-2, 4)); // 16
//
// // 12.Math.sqrt(x) -> 一个数的平方根。
// // x,必需。必须是大于等于 0 的数。
// // 如果 x 小于 0,则返回 NaN。
// // Math.pow() 方法可以计算一个数的任意次根。
// console.log("\n12.");
// console.log(Math.sqrt(0)); // 0
// console.log(Math.sqrt(1)); // 1
// console.log(Math.sqrt(9)); // 3
// console.log(Math.pow(9, 1 / 2)); // 3
// console.log(Math.pow(27, 1 / 3)); // 3
// console.log(Math.sqrt(0.64)); // 0.8
// console.log(Math.pow(0.64, 1 / 2)); // 0.8
// console.log(Math.sqrt(-9)); // NaN
//
// // 13.toDegree(radian) -> 弧度 radian 对应的角度。
// // toRadian(degree) -> 角度 degree 对应的弧度。
// console.log("\n13.");
//
// function toDegree(radian) {
// /*弧度转角度。
// * radian, 待转换的弧度。
// * return 转换后的角度。*/
// return radian / Math.PI * 180;
// }
//
// function toRadian(degree) {
// /*角度转弧度。
// * degree, 待转换的角度。
// * return 转换后的弧度。*/
// return degree / 180 * Math.PI;
// }
//
// console.log("degree:", toDegree(Math.PI));
// console.log("radian:", toRadian(180));
// // degree: 180
// // radian: 3.141592653589793
</script>
</body>
</html>