From 5aa7bdfec9c5fcdfee1c8a0135b9955b9514cace Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 8 Jul 2019 07:47:48 +0100 Subject: [PATCH] fix unit test fp create fns --- src/ieee754/fpcommon/test/unit_test_double.py | 5 ++++- src/ieee754/fpcommon/test/unit_test_half.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ieee754/fpcommon/test/unit_test_double.py b/src/ieee754/fpcommon/test/unit_test_double.py index fca61ead..bb40f92f 100644 --- a/src/ieee754/fpcommon/test/unit_test_double.py +++ b/src/ieee754/fpcommon/test/unit_test_double.py @@ -10,6 +10,9 @@ def get_mantissa(x): def get_exponent(x): return ((x & 0x7ff0000000000000) >> 52) - 1023 +def set_exponent(x, e): + return (x & ~0x7ff0000000000000) | ((e+1023) << 23) + def get_sign(x): return ((x & 0x8000000000000000) >> 63) @@ -34,7 +37,7 @@ def match(x, y): ) def create(s, e, m): - return (s<<63) | ((e+1023) << 52) | m + return set_exponent((s<<63) | m, e) def inf(s): return create(s, 1024, 0) diff --git a/src/ieee754/fpcommon/test/unit_test_half.py b/src/ieee754/fpcommon/test/unit_test_half.py index e00a1b87..fd3a7649 100644 --- a/src/ieee754/fpcommon/test/unit_test_half.py +++ b/src/ieee754/fpcommon/test/unit_test_half.py @@ -8,7 +8,10 @@ def get_mantissa(x): return 0x3ff & x def get_exponent(x): - return ((x & 0xf800) >> 11) - 15 + return ((x & 0x7800) >> 11) - 15 + +def set_exponent(x, e): + return (x & ~0x7800) | ((e+15) << 11) def get_sign(x): return ((x & 0x8000) >> 15) @@ -34,7 +37,7 @@ def match(x, y): ) def create(s, e, m): - return (s<<15) | ((e+15) << 11) | m + return set_exponent((s<<15) | m, x) def inf(s): return create(s, 16, 0) -- 2.30.2