From 4d642810ecb432520198cf7fe7e07f33fa2b61a7 Mon Sep 17 00:00:00 2001 From: Emre Hasegeli Date: Thu, 2 Nov 2017 12:21:19 +0100 Subject: [PATCH 5/6] float-zero-v01 Check for float -0 after multiplications and divisions --- src/include/utils/float.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/include/utils/float.h b/src/include/utils/float.h index c9f5fd30ca..021732d5c6 100644 --- a/src/include/utils/float.h +++ b/src/include/utils/float.h @@ -215,64 +215,76 @@ float8_mi(float8 val1, float8 val2) static inline float4 float4_mul(float4 val1, float4 val2) { float4 result; result = val1 * val2; check_float4_val(result, isinf(val1) || isinf(val2), val1 == 0.0f || val2 == 0.0f); + if (result == -0.0f) + result = 0.0f; + return result; } static inline float8 float8_mul(float8 val1, float8 val2) { float8 result; result = val1 * val2; check_float8_val(result, isinf(val1) || isinf(val2), val1 == 0.0 || val2 == 0.0); + if (result == -0.0) + result = 0.0; + return result; } static inline float4 float4_div(float4 val1, float4 val2) { float4 result; if (val2 == 0.0f) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); result = val1 / val2; check_float4_val(result, isinf(val1) || isinf(val2), val1 == 0.0f); + if (result == -0.0f) + result = 0.0f; + return result; } static inline float8 float8_div(float8 val1, float8 val2) { float8 result; if (val2 == 0.0) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); result = val1 / val2; check_float8_val(result, isinf(val1) || isinf(val2), val1 == 0.0); + if (result == -0.0) + result = 0.0; + return result; } /* * Routines for NaN-aware comparisons * * We consider all NANs to be equal and larger than any non-NAN. This is * somewhat arbitrary; the important thing is to have a consistent sort * order. */ -- 2.13.6 (Apple Git-96)