1 |
|
2 |
|
3 | # Function equal
|
4 |
|
5 | Test whether two values are equal.
|
6 |
|
7 | The function tests whether the relative difference between x and y is
|
8 | smaller than the configured epsilon. The function cannot be used to
|
9 | compare values smaller than approximately 2.22e-16.
|
10 |
|
11 | For matrices, the function is evaluated element wise.
|
12 | In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
|
13 |
|
14 | Values `null` and `undefined` are compared strictly, thus `null` is only
|
15 | equal 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
|
22 | math.equal(x, y)
|
23 | ```
|
24 |
|
25 | ### Parameters
|
26 |
|
27 | Parameter | Type | Description
|
28 | --------- | ---- | -----------
|
29 | `x` | number | BigNumber | boolean | Complex | Unit | string | Array | Matrix | First value to compare
|
30 | `y` | number | BigNumber | boolean | Complex | Unit | string | Array | Matrix | Second value to compare
|
31 |
|
32 | ### Returns
|
33 |
|
34 | Type | Description
|
35 | ---- | -----------
|
36 | boolean | Array | Matrix | Returns true when the compared values are equal, else returns false
|
37 |
|
38 |
|
39 | ## Examples
|
40 |
|
41 | ```js
|
42 | math.equal(2 + 2, 3) // returns false
|
43 | math.equal(2 + 2, 4) // returns true
|
44 |
|
45 | const a = math.unit('50 cm')
|
46 | const b = math.unit('5 m')
|
47 | math.equal(a, b) // returns true
|
48 |
|
49 | const c = [2, 5, 1]
|
50 | const d = [2, 7, 1]
|
51 |
|
52 | math.equal(c, d) // returns [true, false, true]
|
53 | math.deepEqual(c, d) // returns false
|
54 |
|
55 | math.equal("1000", "1e3") // returns true
|
56 | math.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)
|