0005-float-zero-v03.patch
application/octet-stream
Filename: 0005-float-zero-v03.patch
Type: application/octet-stream
Part: 4
Patch
Format: format-patch
Series: patch v3-0005
Subject: float-zero-v03
| File | + | − |
|---|---|---|
| src/include/utils/float.h | 12 | 0 |
From 522c25447dd130b9631e430899f3e639e3990508 Mon Sep 17 00:00:00 2001
From: Emre Hasegeli <emre@hasegeli.com>
Date: Thu, 2 Nov 2017 12:21:19 +0100
Subject: [PATCH 5/6] float-zero-v03
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 b1f34183de..7370d92452 100644
--- a/src/include/utils/float.h
+++ b/src/include/utils/float.h
@@ -213,64 +213,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.14.3 (Apple Git-98)