From: Luke Kenneth Casson Leighton Date: Mon, 10 Feb 2020 14:40:20 +0000 (+0000) Subject: bug #113, add range-limited random numbers more likely to get within the X-Git-Tag: ls180-24jan2020~209 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=031fafb3112f83dea18443f0c0b9e43418789e61;p=ieee754fpu.git bug #113, add range-limited random numbers more likely to get within the target range of the integer to be converted to --- diff --git a/src/ieee754/fcvt/test/rangelimited.py b/src/ieee754/fcvt/test/rangelimited.py new file mode 100644 index 00000000..c81e2c37 --- /dev/null +++ b/src/ieee754/fcvt/test/rangelimited.py @@ -0,0 +1,34 @@ +"""creates fp numbers that are range-limited + +to properly test FPtoFP (higher to lower) and FPtoINT (higher to lower) +it's no good having FP numbers that, statistically 99.99% of the time, +are going to be converted to INF (max of the int or float). + +therefore, numbers need to be *specifically* generated that have a high +probability of being within the target range or just outside of it +""" + +from random import randint +from sfpy import Float16, Float32, Float64 + +def create_ranged_float(fkls, mainwid, fracwid): + """create a floating-point number + + range: +/- twice the bit-range + fractional part: to ensure that there's plenty to play with + """ + mainwid = 1<