From bea9840ef1a9e0c7b7c33a4950088c732befa563 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 28 Feb 2010 10:37:04 +0000 Subject: [PATCH] hash-long-double-aux.cc (hash:: operator()(long double)): Hash both -0 and +0 to 0. 2010-02-28 Paolo Carlini * src/hash-long-double-aux.cc (hash:: operator()(long double)): Hash both -0 and +0 to 0. From-SVN: r157120 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/src/hash-long-double-aux.cc | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 564f905cbe0a..ef97ea3c0cf6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2010-02-28 Paolo Carlini + + * src/hash-long-double-aux.cc (hash:: + operator()(long double)): Hash both -0 and +0 to 0. + 2010-02-25 Ed Smith-Rowland <3dw4rd@verizon.net> * include/bits/random.tcc (operator<<): Use max_digits10. diff --git a/libstdc++-v3/src/hash-long-double-aux.cc b/libstdc++-v3/src/hash-long-double-aux.cc index 5b8bbfdd49de..d54d635f83e6 100644 --- a/libstdc++-v3/src/hash-long-double-aux.cc +++ b/libstdc++-v3/src/hash-long-double-aux.cc @@ -28,7 +28,9 @@ size_t hash::operator()(long double __val) const { - size_t __result = 0; + // 0 and -0 both hash to zero. + if (__val == 0.0L) + return 0; int __exponent; __val = __builtin_frexpl(__val, &__exponent); @@ -44,7 +46,5 @@ const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; - __result = __hibits + (size_t)__val + __coeff * __exponent; - - return __result; + return __hibits + (size_t)__val + __coeff * __exponent; }