mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 10:50:05 +00:00
Change hashing rules for float-like types to make 0 == -0
This commit is contained in:
@@ -1439,6 +1439,11 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) {
|
||||
|
||||
case Type_Info_Complex:
|
||||
switch v in a {
|
||||
case complex32:
|
||||
if imag(v) == 0 {
|
||||
value = f64(real(v))
|
||||
valid = true
|
||||
}
|
||||
case complex64:
|
||||
if imag(v) == 0 {
|
||||
value = f64(real(v))
|
||||
@@ -1453,6 +1458,11 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) {
|
||||
|
||||
case Type_Info_Quaternion:
|
||||
switch v in a {
|
||||
case quaternion64:
|
||||
if imag(v) == 0 && jmag(v) == 0 && kmag(v) == 0 {
|
||||
value = f64(real(v))
|
||||
valid = true
|
||||
}
|
||||
case quaternion128:
|
||||
if imag(v) == 0 && jmag(v) == 0 && kmag(v) == 0 {
|
||||
value = f64(real(v))
|
||||
@@ -1646,13 +1656,40 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_
|
||||
return equal(va, vb, including_indirect_array_recursion, recursion_level+1)
|
||||
case Type_Info_Map:
|
||||
return false
|
||||
case Type_Info_Float:
|
||||
x, _ := as_f64(a)
|
||||
y, _ := as_f64(b)
|
||||
return x == y
|
||||
case Type_Info_Complex:
|
||||
switch x in a {
|
||||
case complex32:
|
||||
#no_type_assert y := b.(complex32)
|
||||
return x == y
|
||||
case complex64:
|
||||
#no_type_assert y := b.(complex64)
|
||||
return x == y
|
||||
case complex128:
|
||||
#no_type_assert y := b.(complex128)
|
||||
return x == y
|
||||
}
|
||||
return false
|
||||
case Type_Info_Quaternion:
|
||||
switch x in a {
|
||||
case quaternion64:
|
||||
#no_type_assert y := b.(quaternion64)
|
||||
return x == y
|
||||
case quaternion128:
|
||||
#no_type_assert y := b.(quaternion128)
|
||||
return x == y
|
||||
case quaternion256:
|
||||
#no_type_assert y := b.(quaternion256)
|
||||
return x == y
|
||||
}
|
||||
return false
|
||||
case
|
||||
Type_Info_Boolean,
|
||||
Type_Info_Integer,
|
||||
Type_Info_Rune,
|
||||
Type_Info_Float,
|
||||
Type_Info_Complex,
|
||||
Type_Info_Quaternion,
|
||||
Type_Info_Type_Id,
|
||||
Type_Info_Pointer,
|
||||
Type_Info_Multi_Pointer,
|
||||
|
||||
Reference in New Issue
Block a user