From da01094c82c4569fe529664ccbb044cca0c19e63 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 14:44:49 +0100 Subject: [PATCH] add some functions copied from unit_test_single for mantissa/exponent handling --- src/add/fsqrt.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index 3a8f8905..72850314 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -45,6 +45,21 @@ def sqrt(num): return Q +# grabbed these from unit_test_single (convenience, this is just experimenting) + +def get_mantissa(x): + return 0x7fffff & x + +def get_exponent(x): + return ((x & 0x7f800000) >> 23) - 127 + +def set_exponent(x, e): + return (x & ~0x7f800000) | ((e+127) << 23) + +def get_sign(x): + return ((x & 0x80000000) >> 31) + + def main(mantissa, exponent): if exponent & 1 != 0: return sqrt(mantissa << 1), # shift mantissa up -- 2.30.2