From: Luke Kenneth Casson Leighton Date: Tue, 11 Feb 2020 19:17:51 +0000 (+0000) Subject: add range-focussed fp64/32-to-32/16 downconversion tests X-Git-Tag: ls180-24jan2020~197 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=954fb4ed16848687c8ae2d396ebbfbc55003def2;p=ieee754fpu.git add range-focussed fp64/32-to-32/16 downconversion tests these create a number that is *almost* in the target range so that it will hit the min/max (inf) limit some of the time but not all --- diff --git a/src/ieee754/fcvt/test/rangelimited.py b/src/ieee754/fcvt/test/rangelimited.py index c81e2c37..eacb3534 100644 --- a/src/ieee754/fcvt/test/rangelimited.py +++ b/src/ieee754/fcvt/test/rangelimited.py @@ -11,6 +11,26 @@ 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_target(fkls, target): + """create a targetted floating-point number just within + the min/max range, by +/- 0.5% + """ + if randint(0, 1) == 1: + target = -target + res = fkls(target) + fracwid = 1<<50 # biiig number... + frac = float(randint(0, fracwid)-fracwid/2) / (fracwid/2) # +/- 0.99999 + frac = (frac + 500.0) / 500.0 # change to 0.1% + res = res * fkls(frac) + + return res.bits + +def create_ranged_fp16(fkls): + return create_ranged_target(fkls, 65519.0) + +def create_ranged_fp32(fkls): + return create_ranged_target(fkls, 3.402823466E38) + def create_ranged_float(fkls, mainwid, fracwid): """create a floating-point number @@ -32,3 +52,14 @@ def create_int(fkls, intwid): """ return create_ranged_float(fkls, intwid+1, intwid+1) +if __name__ == '__main__': + for i in range(10): + x = create_ranged_fp16(Float32) + print (Float32(x)) + x = Float32(x) + print (Float16(x)) + for i in range(10): + x = create_ranged_fp32(Float64) + print (Float64(x)) + x = Float64(x) + print (Float32(x)) diff --git a/src/ieee754/part_bits/__init__.py b/src/ieee754/part_bits/__init__.py new file mode 100644 index 00000000..e69de29b