-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.js
More file actions
75 lines (55 loc) · 2.43 KB
/
Math.js
File metadata and controls
75 lines (55 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
console.log("Pi:",Math.PI);
var num= 4.3;
console.log("round:" ,Math.round(num));
var num2 = 5.8;
console.log("floor:",Math.floor(num2));
var num3 = 5.7;
console.log("ceil:" , Math.ceil(num3));
console.log(Math.floor(Math.random(3)*10) + 1)
console.log(Math.abs(-3));
console.log(Math.sqrt(25))
// // --------------------
// // Math Properties
// // --------------------
// console.log("Math.PI =", Math.PI); // π = 3.14159...
// console.log("Math.E =", Math.E); // Euler's number = 2.718...
// console.log("Math.SQRT2 =", Math.SQRT2); // √2 ≈ 1.414
// console.log("Math.SQRT1_2 =", Math.SQRT1_2); // 1/√2 ≈ 0.707
// console.log("Math.LN2 =", Math.LN2); // Natural log of 2 ≈ 0.693
// console.log("Math.LN10 =", Math.LN10); // Natural log of 10 ≈ 2.302
// // --------------------
// // 1. Rounding Numbers
// // --------------------
// console.log("Math.round(4.6) =", Math.round(4.6)); // 5 (nearest integer)
// console.log("Math.ceil(4.2) =", Math.ceil(4.2)); // 5 (always up)
// console.log("Math.floor(4.9) =", Math.floor(4.9)); // 4 (always down)
// console.log("Math.trunc(4.9) =", Math.trunc(4.9)); // 4 (remove decimal part)
// // --------------------
// // 2. Power and Roots
// // --------------------
// console.log("Math.pow(2, 3) =", Math.pow(2, 3)); // 8 (2³)
// console.log("Math.sqrt(16) =", Math.sqrt(16)); // 4 (√16)
// // --------------------
// // 3. Absolute & Sign
// // --------------------
// console.log("Math.abs(-7) =", Math.abs(-7)); // 7 (absolute value)
// console.log("Math.sign(10) =", Math.sign(10)); // 1 (positive number)
// console.log("Math.sign(-5) =", Math.sign(-5)); // -1 (negative number)
// console.log("Math.sign(0) =", Math.sign(0)); // 0
// // --------------------
// // 4. Min & Max
// // --------------------
// console.log("Math.min(5, 2, 9) =", Math.min(5, 2, 9)); // 2
// console.log("Math.max(5, 2, 9) =", Math.max(5, 2, 9)); // 9
// // --------------------
// // 5. Random Number
// // --------------------
// console.log("Math.random() =", Math.random()); // random decimal between 0 and 1
// // Random number between 1 and 10
// console.log("Random 1-10 =", Math.floor(Math.random() * 10) + 1);
// // --------------------
// // 6. Trigonometry
// // --------------------
// console.log("Math.sin(0) =", Math.sin(0)); // 0
// console.log("Math.cos(Math.PI) =", Math.cos(Math.PI));// -1
// console.log("Math.tan(Math.PI/4) =", Math.tan(Math.PI/4)); // ≈ 1