Tag

negative-zero

0 views collected around this technical thread.

Top Architect
Top Architect
Jan 23, 2022 · Fundamentals

Understanding Java Float hashCode: Why -0.0 and 0.0 Behave Differently as Map Keys

This article explains how Java's Float hashCode treats 0.0 and -0.0 as distinct values, causing unexpected behavior when using floating‑point numbers as HashMap keys, and shows how to debug, reproduce, and avoid the issue by using alternative representations.

HashCodeHashMapJava
0 likes · 10 min read
Understanding Java Float hashCode: Why -0.0 and 0.0 Behave Differently as Map Keys