From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 13:44:49 +0000 (+0100) Subject: add some functions copied from unit_test_single for mantissa/exponent handling X-Git-Tag: ls180-24jan2020~1158 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=da01094c82c4569fe529664ccbb044cca0c19e63;p=ieee754fpu.git add some functions copied from unit_test_single for mantissa/exponent handling --- 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