From 1aaea99652a8cc66c01f63ee473c4ee7a4a42bdd Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 14:52:11 +0100 Subject: [PATCH] add convenience routines --- src/add/fsqrt.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 -- 2.30.2