函数 equal #
测试两个值是否相等。
该函数测试 x 和 y 之间的相对差是否小于配置的 relTol 和 absTol。该函数不能用于比较小于约 2.22e-16 的值。
对于矩阵,该函数逐元素进行计算。对于复数,x.re 必须等于 y.re,x.im 必须等于 y.im。
值 null 和 undefined 进行严格比较,因此 null 仅等于 null,而不等于其他任何值,undefined 仅等于 undefined,而不等于其他任何值。字符串按其数值进行比较。
Syntax #
math.equal(x, y)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
number | BigNumber | bigint | boolean | Complex | Unit | string | Array | Matrix | 要比较的第一个值 |
y |
number | BigNumber | bigint | boolean | Complex | Unit | string | Array | Matrix | 要比较的第二个值 |
Returns #
| Type | Description |
|---|---|
| boolean | Array | Matrix | 当比较的值相等时返回 true,否则返回 false。 |
Throws #
Type | Description —- | ———–
Examples #
math.equal(2 + 2, 3) // returns false
math.equal(2 + 2, 4) // returns true
const a = math.unit('50 cm')
const b = math.unit('5 m')
math.equal(a, b) // returns true
const c = [2, 5, 1]
const d = [2, 7, 1]
math.equal(c, d) // returns [true, false, true]
math.deepEqual(c, d) // returns false
math.equal("1000", "1e3") // returns true
math.equal(0, null) // returns false
另请参阅 #
unequal, smaller, smallerEq, larger, largerEq, compare, deepEqual, equalText