mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 13:06:22 +00:00
43 lines
808 B
Markdown
43 lines
808 B
Markdown
|
---
|
||
|
id: 1accac75-7a5c-4847-977a-f0ae63454820
|
||
|
title: JavaScript Math library
|
||
|
---
|
||
|
|
||
|
# ES6
|
||
|
|
||
|
## .sign(x)
|
||
|
|
||
|
### Returns
|
||
|
|
||
|
- -1 if x is a negative number (including -Infinity).
|
||
|
- 0 if x is zero4.
|
||
|
- +1 if x is a positive number (including Infinity).
|
||
|
- NaN if x is NaN or not a number.
|
||
|
|
||
|
``` javascript
|
||
|
console.log(Math.sign(-8)) // -a
|
||
|
console.log(Math.sign(3)) // 1
|
||
|
console.log(Math.sign(0)) // 0
|
||
|
console.log(Math.sign(NaN)) // NaN
|
||
|
console.log(Math.sign(-Infinity)) // -1
|
||
|
console.log(Math.sign(Infinity)) // 1
|
||
|
```
|
||
|
|
||
|
## .trunc(x)
|
||
|
|
||
|
``` javascript
|
||
|
console.log(Math.trunc(3.1)) // 3
|
||
|
console.log(Math.trunc(3.9)) // 3
|
||
|
console.log(Math.trunc(-3.1)) // 3
|
||
|
console.log(Math.trunc(-3.9)) // 3
|
||
|
```
|
||
|
|
||
|
## .cbrt(x)
|
||
|
|
||
|
Returns the cube root of x:
|
||
|
|
||
|
``` javascript
|
||
|
console.log(Math.cbrt(8)) // 2
|
||
|
console.log(Math.cbrt(27)) // 3
|
||
|
```
|