equal.md (1992B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 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 ### Throws 40 41 Type | Description 42 ---- | ----------- 43 44 45 ## Examples 46 47 ```js 48 math.equal(2 + 2, 3) // returns false 49 math.equal(2 + 2, 4) // returns true 50 51 const a = math.unit('50 cm') 52 const b = math.unit('5 m') 53 math.equal(a, b) // returns true 54 55 const c = [2, 5, 1] 56 const d = [2, 7, 1] 57 58 math.equal(c, d) // returns [true, false, true] 59 math.deepEqual(c, d) // returns false 60 61 math.equal("1000", "1e3") // returns true 62 math.equal(0, null) // returns false 63 ``` 64 65 66 ## See also 67 68 [unequal](unequal.md), 69 [smaller](smaller.md), 70 [smallerEq](smallerEq.md), 71 [larger](larger.md), 72 [largerEq](largerEq.md), 73 [compare](compare.md), 74 [deepEqual](deepEqual.md), 75 [equalText](equalText.md)