Skip to content

Commit b30cc0f

Browse files
committed
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 ce773f2. Rearrange so that we use the result of get_float8_nan() for all NaN cases. As before, back-patch.
1 parent ac5ea66 commit b30cc0f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/backend/access/hash/hashfunc.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ hashfloat4(PG_FUNCTION_ARGS)
151151
if (key == (float4) 0)
152152
PG_RETURN_UINT32(0);
153153

154-
/*
155-
* Similarly, NaNs can have different bit patterns but they should all
156-
* compare as equal. For backwards-compatibility reasons we force them to
157-
* have the hash value of a standard NaN.
158-
*/
159-
if (isnan(key))
160-
key = get_float4_nan();
161-
162154
/*
163155
* To support cross-type hashing of float8 and float4, we want to return
164156
* the same hash value hashfloat8 would produce for an equal float8 value.
@@ -168,6 +160,16 @@ hashfloat4(PG_FUNCTION_ARGS)
168160
*/
169161
key8 = key;
170162

163+
/*
164+
* Similarly, NaNs can have different bit patterns but they should all
165+
* compare as equal. For backwards-compatibility reasons we force them to
166+
* have the hash value of a standard float8 NaN. (You'd think we could
167+
* replace key with a float4 NaN and then widen it; but on some old
168+
* platforms, that way produces a different bit pattern.)
169+
*/
170+
if (isnan(key8))
171+
key8 = get_float8_nan();
172+
171173
return hash_any((unsigned char *) &key8, sizeof(key8));
172174
}
173175

@@ -181,9 +183,9 @@ hashfloat4extended(PG_FUNCTION_ARGS)
181183
/* Same approach as hashfloat4 */
182184
if (key == (float4) 0)
183185
PG_RETURN_UINT64(seed);
184-
if (isnan(key))
185-
key = get_float4_nan();
186186
key8 = key;
187+
if (isnan(key8))
188+
key8 = get_float8_nan();
187189

188190
return hash_any_extended((unsigned char *) &key8, sizeof(key8), seed);
189191
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy