From fceaa46dda37a2d4db4e0a48cc1dab3fe208cb2c Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 28 Nov 2015 09:28:35 +0100 Subject: [PATCH] Test HINCRBYFLOAT rounding only in x86_64 and when valgrind is not in use. 64 bit double math is not enough to make the test passing, and rounding to 1.2999999 instead of 1.23 is not an error in the implementation. Valgrind and sometimes other archs are not able to work with 80 bit doubles. --- tests/unit/type/hash.tcl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/unit/type/hash.tcl b/tests/unit/type/hash.tcl index 1c060087..02560ede 100644 --- a/tests/unit/type/hash.tcl +++ b/tests/unit/type/hash.tcl @@ -516,10 +516,21 @@ start_server {tags {"hash"}} { } } - test {Test HINCRBYFLOAT for correct float representation (issue #2846)} { - r del myhash - assert {[r hincrbyfloat myhash float 1.23] eq {1.23}} - assert {[r hincrbyfloat myhash float 0.77] eq {2}} - assert {[r hincrbyfloat myhash float -0.1] eq {1.9}} + # The following test can only be executed if we don't use Valgrind, and if + # we are using x86_64 architecture, because: + # + # 1) Valgrind has floating point limitations, no support for 80 bits math. + # 2) Other archs may have the same limits. + # + # 1.23 cannot be represented correctly with 64 bit doubles, so we skip + # the test, since we are only testing pretty printing here and is not + # a bug if the program outputs things like 1.299999... + if {!$::valgrind || ![string match *x86_64* [exec uname -a]]} { + test {Test HINCRBYFLOAT for correct float representation (issue #2846)} { + r del myhash + assert {[r hincrbyfloat myhash float 1.23] eq {1.23}} + assert {[r hincrbyfloat myhash float 0.77] eq {2}} + assert {[r hincrbyfloat myhash float -0.1] eq {1.9}} + } } }