-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path36_math.js
55 lines (35 loc) · 2.06 KB
/
36_math.js
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
// JavaScript provides a variety of built -in math methods that you can use to perform mathematical operations on numbers.Here are some of the most commonly used math methods in JavaScript:
// Math.abs(x) : Returns the absolute value of a number.
//Math.ceil(x) : Returns the smallest integer greater than or equal to a number.
//Math.floor(x) : Returns the largest integer less than or equal to a number.
//Math.round(x) : Returns the value of a number rounded to the nearest integer.
//Math.max(x1, x2, ..., xn) : Returns the largest of zero or more numbers.
//Math.min(x1, x2, ..., xn) : Returns the smallest of zero or more numbers.
//Math.random() : Returns a random number between 0 and 1.
// Math.pow(x, y) : Returns the value of x to the power of y.
//Math.sqrt(x) : Returns the square root of a number.
//Math.exp(x) : Returns the value of e to the power of x.
//Math.log(x) : Returns the natural logarithm(base e) of a number.
//Math.sin(x) : Returns the sine of a number.
//Math.cos(x) : Returns the cosine of a number.
//Math.tan(x) : Returns the tangent of a number.
//Math.PI : Represents the ratio of the circumference of a circle to its diameter, approximately equal to 3.14159.
// Here is an example of how to use some of these math methods in JavaScript:
// let x = -5.5;
// let y = 10;
// console.log(Math.abs(x)); // 5.5
// console.log(Math.ceil(x)); // -5
// console.log(Math.floor(x)); // -6
// console.log(Math.round(x)); // -6
// console.log(Math.max(x, y)); // 10
// console.log(Math.min(x, y)); // -5.5
// console.log(Math.random()); // a random number between 0 and 1
// console.log(Math.pow(y, 2)); // 100
// console.log(Math.sqrt(y)); // 3.1622776601683795
// console.log(Math.exp(y)); // 22026.465794806718
// console.log(Math.log(y)); // 2.302585092994046
// console.log(Math.sin(y)); // -0.5440211108893698
// console.log(Math.cos(y)); // -0.8390715290764524
// console.log(Math.tan(y)); // 0.6483608274590866
// console.log(Math.PI); // 3.141592653589793
// By using these math methods, you can easily perform mathematical operations on numbers in JavaScript.