UNPKG

1.25 kBJavaScriptView Raw
1/**
2 * Common Math expressions.
3 *
4 * @module math
5 */
6
7export const floor = Math.floor
8export const ceil = Math.ceil
9export const abs = Math.abs
10export const imul = Math.imul
11export const round = Math.round
12export const log10 = Math.log10
13export const log2 = Math.log2
14export const log = Math.log
15export 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 */
23export 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 */
31export 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 */
39export const max = (a, b) => a > b ? a : b
40
41export const isNaN = Number.isNaN
42
43export 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 */
50export const exp10 = exp => Math.pow(10, exp)
51
52export 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 */
58export const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0