From 9ad0850301045e0d7fd243340e807fb2c9f736de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20Cosmin=20R=C4=83dulescu?= Date: Tue, 4 Oct 2016 10:57:16 +0200 Subject: [PATCH] Fixes hash float negative 0 problem Before this was giving an error: var a = {Vector2(1, 0): 5, Vector2(-1, 0): 7} print(a) print(a[Vector2(1, 0)]) print(a[-Vector2(1, 0)]) This simple commit fixes the issue. --- core/hashfuncs.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/hashfuncs.h b/core/hashfuncs.h index a917ee5edb8..6c029a34589 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -74,7 +74,10 @@ static inline uint32_t hash_djb2_one_float(float p_in,uint32_t p_prev=5381) { float f; uint32_t i; } u; - u.f=p_in; + + // handle -0 case + if (p_in==0.0f) u.f=0.0f; + else u.f=p_in; return ((p_prev<<5)+p_prev)+u.i; }