1 | /**
|
2 | * Common Math expressions.
|
3 | *
|
4 | * @module math
|
5 | */
|
6 |
|
7 | export const floor = Math.floor
|
8 | export const ceil = Math.ceil
|
9 | export const abs = Math.abs
|
10 | export const imul = Math.imul
|
11 | export const round = Math.round
|
12 | export const log10 = Math.log10
|
13 | export const log2 = Math.log2
|
14 | export const log = Math.log
|
15 | export const sqrt = Math.sqrt
|
16 |
|
17 | /**
|
18 | * @function
|
19 | * @param {number} a
|
20 | * @param {number} b
|
21 | * @return {number} The sum of a and b
|
22 | */
|
23 | export const add = (a, b) => a + b
|
24 |
|
25 | /**
|
26 | * @function
|
27 | * @param {number} a
|
28 | * @param {number} b
|
29 | * @return {number} The smaller element of a and b
|
30 | */
|
31 | export const min = (a, b) => a < b ? a : b
|
32 |
|
33 | /**
|
34 | * @function
|
35 | * @param {number} a
|
36 | * @param {number} b
|
37 | * @return {number} The bigger element of a and b
|
38 | */
|
39 | export const max = (a, b) => a > b ? a : b
|
40 |
|
41 | export const isNaN = Number.isNaN
|
42 |
|
43 | export const pow = Math.pow
|
44 | /**
|
45 | * Base 10 exponential function. Returns the value of 10 raised to the power of pow.
|
46 | *
|
47 | * @param {number} exp
|
48 | * @return {number}
|
49 | */
|
50 | export const exp10 = exp => Math.pow(10, exp)
|
51 |
|
52 | export const sign = Math.sign
|
53 |
|
54 | /**
|
55 | * @param {number} n
|
56 | * @return {boolean} Wether n is negative. This function also differentiates between -0 and +0
|
57 | */
|
58 | export const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0
|