Quirrel4.53.0

deep.is_strict_equal

Defined in module "deep"
from "deep" import is_strict_equal
is_strict_equal(a, b, [comparers: table|null]): any

Compares as is_relaxed_equal() does, but numbers are equal only with the same type and the same bits

Parameters

aanythe first value
banythe second value
comparerstable|nullan optional table of compare functions, or null, as for is_relaxed_equal optional

Return value

The value that a compare function or an isEqual() method returns when it decides for a and b themselves, else true or false.

Errors

The same as for is_relaxed_equal.

Notes

Step 1 of is_relaxed_equal is a == b. This function compares the type and the bits instead, so 1 and 1.0 are not equal, 0.0 and -0.0 are not equal, and a NaN is equal to a NaN with the same bits. Other values are equal as with ==: the same object or the same string. Compare functions, len() calls and isEqual() methods are called as for is_relaxed_equal, so a float key of comparers still decides for two floats that are not the same.

Example

examples/deep/is_strict_equal.nut
from "deep" import is_relaxed_equal, is_strict_equal
from "math" import sqrt

println(is_relaxed_equal([1, 0.0], [1.0, -0.0]), is_strict_equal([1, 0.0], [1.0, -0.0]))
println(is_strict_equal({ id = 1, at = [0.5, 2] }, { id = 1, at = [0.5, 2] }))

let nan = sqrt(-1.0)
println(nan == nan, is_strict_equal([nan], [nan]))
Output:
true false
true
false true

See also

is_relaxed_equalCompares two values deeply: equal tables and arrays, and instances by their isEqual() method
copyCopies tables and arrays deeply, as deep_clone() of underscore.nut does
deepmodule index