From 031fafb3112f83dea18443f0c0b9e43418789e61 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 10 Feb 2020 14:40:20 +0000 Subject: [PATCH] bug #113, add range-limited random numbers more likely to get within the target range of the integer to be converted to --- src/ieee754/fcvt/test/rangelimited.py | 34 ++++++++++++++ src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py | 45 +++++++++++++++---- 2 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/ieee754/fcvt/test/rangelimited.py 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<