postgres.git / summary / log / commit / refs

commit    a5e8f7b3798b6fb9a4f3129a5eab98b7087c8a80
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Sat Sep 04 20:29:08 2021 +0000
First released in: 15.0, 9.6.24, 10.19, 11.14, 12.9, 13.5, 14.0

    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.


src/backend/access/hash/hashfunc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c index b2422260f61..7522921c4f1 100644 --- a/src/backend/access/hash/hashfunc.c +++ b/src/backend/access/hash/hashfunc.c @@ -100,14 +100,6 @@ hashfloat4(PG_FUNCTION_ARGS) if (key == (float4) 0) 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. @@ -117,6 +109,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)); } [parent: 121cdaff1068]