From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 13:52:11 +0000 (+0100) Subject: add convenience routines X-Git-Tag: ls180-24jan2020~1156 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1aaea99652a8cc66c01f63ee473c4ee7a4a42bdd;p=ieee754fpu.git add convenience routines --- diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index c2d32a7a..f82e8dc6 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -60,6 +60,17 @@ def set_exponent(x, e): def get_sign(x): return ((x & 0x80000000) >> 31) +# convert FP32 to s/e/m +def create_fp32(s, e, m): + """ receive sign, exponent, mantissa, return FP32 """ + return set_exponent((s << 31) | get_mantissa(m)) + +# convert s/e/m to FP32 +def decode_fp32(x): + """ receive FP32, return sign, exponent, mantissa """ + return get_sign(x), get_exponent(x), get_mantissa(x) + + # main function, takes mantissa and exponent as separate arguments # returns a tuple, sqrt'd mantissa, sqrt'd exponent