diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-11-04 18:11:15 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-11-04 18:11:15 -0500 |
commit | fac83dbd6fe1ac3d4125bfa39f287f95bffe6cda (patch) | |
tree | b337e030c78f731557298585647d572728c3d973 /src/include/utils/float.h | |
parent | 9e38c2bb5093ceb0c04d6315ccd8975bd17add66 (diff) | |
download | postgresql-fac83dbd6fe1ac3d4125bfa39f287f95bffe6cda.tar.gz postgresql-fac83dbd6fe1ac3d4125bfa39f287f95bffe6cda.zip |
Remove underflow error in float division with infinite divisor.
float4_div and float8_div correctly produced zero for zero divided
by infinity, but threw an underflow error for nonzero finite values
divided by infinity. This seems wrong; at the very least it's
inconsistent with the behavior recently implemented for numeric
infinities. Remove the error and allow zero to be returned.
This patch also removes a useless isinf() test from the overflow
checks in these functions (non-Inf divided by Inf can't produce Inf).
Extracted from a larger patch; this seems significant outside the
context of geometric operators, so it deserves its own commit.
Kyotaro Horiguchi
Discussion: https://postgr.es/m/CAGf+fX70rWFOk5cd00uMfa__0yP+vtQg5ck7c2Onb-Yczp0URA@mail.gmail.com
Diffstat (limited to 'src/include/utils/float.h')
-rw-r--r-- | src/include/utils/float.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/include/utils/float.h b/src/include/utils/float.h index e2aae8ef177..79bf8daca80 100644 --- a/src/include/utils/float.h +++ b/src/include/utils/float.h @@ -225,9 +225,9 @@ float4_div(const float4 val1, const float4 val2) if (unlikely(val2 == 0.0f) && !isnan(val1)) float_zero_divide_error(); result = val1 / val2; - if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2)) + if (unlikely(isinf(result)) && !isinf(val1)) float_overflow_error(); - if (unlikely(result == 0.0f) && val1 != 0.0f) + if (unlikely(result == 0.0f) && val1 != 0.0f && !isinf(val2)) float_underflow_error(); return result; @@ -241,9 +241,9 @@ float8_div(const float8 val1, const float8 val2) if (unlikely(val2 == 0.0) && !isnan(val1)) float_zero_divide_error(); result = val1 / val2; - if (unlikely(isinf(result)) && !isinf(val1) && !isinf(val2)) + if (unlikely(isinf(result)) && !isinf(val1)) float_overflow_error(); - if (unlikely(result == 0.0) && val1 != 0.0) + if (unlikely(result == 0.0) && val1 != 0.0 && !isinf(val2)) float_underflow_error(); return result; |