From 9d3ed820105d97061aa5ce8d32b934cac85df180 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Mon, 19 Oct 2026 01:48:45 +0100 Subject: Pure 027's 5c: {cents:.2d}, an i64 (or a number) in minor units written with its last N digits after a point (1234 at .2d is 12.34, -5 is -0.05), not Python's form, so the random formats test it against Decimal(v).scaleb(-N) written as .Nf (digits on two in five d columns); digits refused off f and d (the diagnostic names .2d), an i64's .2f pointing at .2d; 002's formats say so --- tests/check.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/check.py b/tests/check.py index 17f0417..e66a384 100644 --- a/tests/check.py +++ b/tests/check.py @@ -1352,10 +1352,18 @@ def formats_and_texts(aup, pure_run, work, apps=6, per_app=24): """Pure 027's stage 2a. Random formats ({v:08x}, {x:.3f}, ...) of i64s and numbers a message gives, against Python's format(): an integer's form of a number that is not whole fails as limit, -0 is written as 0. - Then an app that cuts a message's bytes at commas into a text joined by - '|', counting with while and reading by position only where && decides - (an empty message reads nothing), against Python.""" - import struct + .Nd (Pure 027's stage 5) writes an integer in minor units, its last N + digits after a point: the Decimal of v / 10^N in .Nf. Then an app that + cuts a message's bytes at commas into a text joined by '|', counting + with while and reading by position only where && decides (an empty + message reads nothing), against Python.""" + import decimal + + def shown(v, spec): + if '.' in spec and spec.endswith('d'): + return format(decimal.Decimal(v).scaleb(-int(spec.split('.')[1][:-1])), spec[:-1] + 'f') + return format(v, spec) + rng = random.Random(272) checked = faults = 0 for app in range(apps): @@ -1365,7 +1373,7 @@ def formats_and_texts(aup, pure_run, work, apps=6, per_app=24): form = rng.choice('dxXbo' if integer else 'dxXbof') width = rng.choice([0, 0, 1, 5, 8, 20]) zeros = width > 0 and rng.random() < 0.5 - digits = rng.randrange(0, 11) if form == 'f' else None + digits = rng.randrange(0, 11) if form == 'f' or (form == 'd' and rng.random() < 0.4) else None spec = ('0' if zeros else '') + (str(width) if width else '') + (f'.{digits}' if digits is not None else '') + form specs.append((integer, spec)) source = 'state t: text\n' + ''.join(f'input e{i} = message {{\n v: i64\n x: number\n}}\n' for i in range(per_app)) @@ -1380,11 +1388,11 @@ def formats_and_texts(aup, pure_run, work, apps=6, per_app=24): x = rng.choice([rng.uniform(-1e6, 1e6), float(rng.randrange(-5000, 5000)), rng.uniform(-1, 1), -0.0, 2.5, 1e20]) given += f'message e{i} {struct.pack("