JavaScript Scratches
Mathematics 01
JavaScript floating-point format can handle
18,437,736,874,454,810,627 real numbers
unless you are using BigInt.
JavaScript has a large number of 'methods' available dealing with mathematical operations and functions.
Here are some of what may be most useful for you.
Math.sign(x)
Is x positive or negative
Sign of -19.76:
Sign of 19.76:
Sign of (10-2-8):
Math.truncate(x)
Return the integer part of a value
4.9 truncated:
-4.2 truncated:
Math.round(x)
Return the nearest integer
73.56 rounded:
Round a variable:
v rounded:
Math.ceil(x)
Return x rounded up to nearest integer
Ceiling 23.75:
Math.floor(x)Return x rounded down to nearest integer
Floor 23.75:
Exponentiation & Roots
Math.pow(x,y)Return value of x to the power y
72 squared:
99 ** 123:
Math.sqrt(x)Return square root of x
Square root of 7849:
Math.cbrt(x)Return cubic root of x
Cubic root of 7849:
Math.abs()Return absolute (positive) value of x
Absolute value of -7849.973012:
Trig Functions
All JavaScript trig values require and return radians NOT degrees
There are 2π radians in a circle
360° = 2π
1 radian = 57.3°
1 degree = 0.017 radians
Angle in radians = Angle in degrees x π / 180
Math.sin(θ)Return sine of θ radians
Sine of 45 radians:
Math.asin(θ)Return arcsine of θ radians
expects a parameter in the range -1 to 1
returns a value between -PI/2 and PI/2
Arcsine of -.567 radians:
Math.cos(θ)Return cosine of θ radians
Cosine of 45 radians:
Math.acos(x)Return arccosine of θ radians
expects a parameter in the range -1 to 1
returns a value value between 0 and PI
Arccosine of -1 radians:
Math.tan(θ)Return tangent of θ radians
Tangent of 45 radians:
Math.atan(θ)Return arctangent of θ radians
returns a value between -PI/2 and PI/2 radians
Arctangent of 45 radians:
More Math Functions