aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-09-04 16:29:08 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-09-04 16:29:08 -0400
commit8782a84529035baca1639c3680458e2062ef9b44 (patch)
tree329f693040cd4b1f27558d210ebb64d48063a5f9 /src
parentc801c3a1ff73c34fcc7ab22b2dd6a85041e6cef3 (diff)
downloadpostgresql-8782a84529035baca1639c3680458e2062ef9b44.tar.gz
postgresql-8782a84529035baca1639c3680458e2062ef9b44.zip
Further portability tweaks for float4/float8 hash functions.
Attempting to make hashfloat4() look as much as possible like hashfloat8(), I'd figured I could replace NaNs with get_float4_nan() before widening to float8. However, results from protosciurus and topminnow show that on some platforms that produces a different bit-pattern from get_float8_nan(), breaking the intent of ce773f230. Rearrange so that we use the result of get_float8_nan() for all NaN cases. As before, back-patch.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/hash/hashfunc.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index 20f4e408933..accac104d59 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -153,14 +153,6 @@ hashfloat4(PG_FUNCTION_ARGS)
PG_RETURN_UINT32(0);
/*
- * Similarly, NaNs can have different bit patterns but they should all
- * compare as equal. For backwards-compatibility reasons we force them to
- * have the hash value of a standard NaN.
- */
- if (isnan(key))
- key = get_float4_nan();
-
- /*
* To support cross-type hashing of float8 and float4, we want to return
* the same hash value hashfloat8 would produce for an equal float8 value.
* So, widen the value to float8 and hash that. (We must do this rather
@@ -169,6 +161,16 @@ hashfloat4(PG_FUNCTION_ARGS)
*/
key8 = key;
+ /*
+ * Similarly, NaNs can have different bit patterns but they should all
+ * compare as equal. For backwards-compatibility reasons we force them to
+ * have the hash value of a standard float8 NaN. (You'd think we could
+ * replace key with a float4 NaN and then widen it; but on some old
+ * platforms, that way produces a different bit pattern.)
+ */
+ if (isnan(key8))
+ key8 = get_float8_nan();
+
return hash_any((unsigned char *) &key8, sizeof(key8));
}
@@ -182,9 +184,9 @@ hashfloat4extended(PG_FUNCTION_ARGS)
/* Same approach as hashfloat4 */
if (key == (float4) 0)
PG_RETURN_UINT64(seed);
- if (isnan(key))
- key = get_float4_nan();
key8 = key;
+ if (isnan(key8))
+ key8 = get_float8_nan();
return hash_any_extended((unsigned char *) &key8, sizeof(key8), seed);
}