UNPKG

1.94 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function equal
4
5Test whether two values are equal.
6
7The function tests whether the relative difference between x and y is
8smaller than the configured epsilon. The function cannot be used to
9compare values smaller than approximately 2.22e-16.
10
11For matrices, the function is evaluated element wise.
12In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
13
14Values `null` and `undefined` are compared strictly, thus `null` is only
15equal to `null` and nothing else, and `undefined` is only equal to
16`undefined` and nothing else. Strings are compared by their numerical value.
17
18
19## Syntax
20
21```js
22math.equal(x, y)
23```
24
25### Parameters
26
27Parameter | Type | Description
28--------- | ---- | -----------
29`x` | number &#124; BigNumber &#124; boolean &#124; Complex &#124; Unit &#124; string &#124; Array &#124; Matrix | First value to compare
30`y` | number &#124; BigNumber &#124; boolean &#124; Complex &#124; Unit &#124; string &#124; Array &#124; Matrix | Second value to compare
31
32### Returns
33
34Type | Description
35---- | -----------
36boolean &#124; Array &#124; Matrix | Returns true when the compared values are equal, else returns false
37
38
39## Examples
40
41```js
42math.equal(2 + 2, 3) // returns false
43math.equal(2 + 2, 4) // returns true
44
45const a = math.unit('50 cm')
46const b = math.unit('5 m')
47math.equal(a, b) // returns true
48
49const c = [2, 5, 1]
50const d = [2, 7, 1]
51
52math.equal(c, d) // returns [true, false, true]
53math.deepEqual(c, d) // returns false
54
55math.equal("1000", "1e3") // returns true
56math.equal(0, null) // returns false
57```
58
59
60## See also
61
62[unequal](unequal.md),
63[smaller](smaller.md),
64[smallerEq](smallerEq.md),
65[larger](larger.md),
66[largerEq](largerEq.md),
67[compare](compare.md),
68[deepEqual](deepEqual.md),
69[equalText](equalText.md)