From b00288b787cef0e4dd05e7f987df8b7a5068df5c Mon Sep 17 00:00:00 2001
From: rtoy <rtoy>
Date: Wed, 9 Jun 2004 14:50:05 +0000
Subject: [PATCH] sxhash is supposed to return the same value for -0.0 and +0.0
 since they are arithmetically equal.  Do this by adding 0.0 to the number,
 which does nothing to the number, except convert -0.0 to 0.0.

---
 code/hash-new.lisp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/code/hash-new.lisp b/code/hash-new.lisp
index b44fe4c17..3513ddb23 100644
--- a/code/hash-new.lisp
+++ b/code/hash-new.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/hash-new.lisp,v 1.31 2004/05/17 18:05:33 rtoy Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/hash-new.lisp,v 1.32 2004/06/09 14:50:05 rtoy Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -935,12 +935,17 @@
      (etypecase s-expr
        (integer (ldb sxhash-bits-byte s-expr))
        (single-float
-	(let ((bits (single-float-bits s-expr)))
+	;; CLHS says sxhash must return the same thing for +0.0 and
+	;; -0.0.  We get the desired result by adding +0.0, which
+	;; converts -0.0 to 0.0.
+	(let* ((x (+ s-expr 0f0))
+	       (bits (single-float-bits x)))
 	  (ldb sxhash-bits-byte
 	       (logxor (ash bits (- sxmash-rotate-bits)) bits))))
        (double-float
-	(let ((lo (double-float-low-bits s-expr))
-	      (hi (double-float-high-bits s-expr)))
+	(let* ((x (+ s-expr 0d0))
+	       (lo (double-float-low-bits x))
+	       (hi (double-float-high-bits x)))
 	  (ldb sxhash-bits-byte
 	       (logxor (ash lo (- sxmash-rotate-bits)) lo
 		       (ldb sxhash-bits-byte
-- 
GitLab