Equality
The most common way to test equality is with =
For numeric equality (IEEE) use ==
For bytewise equality use identical?
The behavior and names are based on Clojure's implementation. Read their docs here: https://clojure.org/guides/equality
Also check out slosh/tests/equality.slosh for some examples.
-
=-
(= 2 0x2)istrue(comparing an int to a byte) -
(= 2 2.0)isfalse(comparing an int to a float) -
(= 0.0 -0.0)istrue -
(= NaN NaN)isfalse -
state.rsdefines special forms object with keyequalmapped to the name=. -
compile.rsmatches onenv.specials().equaland generates opcodeEQUAL -
exec_loop.rsmaps opcodeEQUALto functionis_equal -
vm.rsis_equalconverts each arg to aValue(in case it needs to be dereferenced) and callsis_equal_pair -
vm.rsis_equal_pairdoes a complex test for equality- check if both args are Byte or Int and if so, converts both to
i64withValue::get_intand compares with rust native== - check if both args are numbers (Byte, Int, or Float) and if so, converts both to
f64withValue::get_floatand compares with rust native==
- check if both args are Byte or Int and if so, converts both to
-
-
==-
(== 1 1.0)istrue(comparing an int to a float) -
(== 0.0 -0.0)istrue -
(== NaN NaN)isfalse -
returns true whenever
=does, but also returns true for numbers that are numerically equal -
when comparing two floats, converts two both to
f64and compares with native f64== -
does not use F56::PartialEq implementation
-
state.rsdefines special forms object with keynumeqmapped to the name==. -
compile.rscallscompile_listwhich callscompile_specialwhich callscompile_mathincompile_math.rs -
compile_math.rscompile_mathmatches onenv.specials().numeqand generates opcodeNUMEQ -
exec_loop.rsmaps opcodeNUMEQto functioncompare_numericand passes a comparator|a,b| a == b -
macros.rscompare_numeric- checks if either argument is a
Floatand if so, converts both tof64withget_primitive_floatmacro and uses the comparator - checks if either argument is a
Intand if so, converts both toi64withget_primitive_intmacro and uses the comparator
- checks if either argument is a
-
-
identical?-
(identical? 1 1)istrue -
(identical? 1 1.0)isfalse(different types) -
(identical? 0.0 -0.0)isfalse(comparing floats with different bit patterns) -
(identical? NaN NaN)might betrueorfalse. There are trillions of different bit patterns that represent NaN in IEEE 754 -
is the only equality comparison that uses
Value::PartialEqimplementation which is always false for different types of Values -
using identical equality for floats causes problems with hashing. #125 identical equality is 'too strict' in that you probably expect that +0 and -0 should hash to the same thing, but they don't rendering hash tables
-
state.rsdefines special forms object with keyeqmapped to the nameidentical?. -
compile.rsmatches onenv.specials().eqand generates opcodeEQ -
exec_loop.rsmaps opcodeEQto functionis_identical -
vm.rsis_identicalconverts each arg to aValue(in case it needs to be dereferenced) and comparesval1 == val2which usesValue::PartialEqimplementation
-
-
assert-equal- based on
= - is a macro defined in core.slosh which checks if the arguments are
=and throws an error if they are not
- based on
-
not=- defined in
vm/core.sloshas the negation of=
- defined in
-
not==- defined in
vm/core.sloshas the negation of==
- defined in