lib/strconv tests: hand-main plumbing -> assert (@test conversion B3)

inttest keeps now-inert per-row id params (rows 1:1 per spec; removal
deferred, ~100 callsites).
This commit is contained in:
2026-06-10 18:52:53 +09:00
parent 56450e68ce
commit b6d9201ef5
3 changed files with 185 additions and 209 deletions

View File

@@ -1,7 +1,7 @@
// ftostest — exercises lib/strconv/ftos.ww (Hare ftos.ha / ftos_ryu.ha
// Ryū port). Run with `out/bin/ww run lib/strconv/test/ftostest.ww`.
// Same signalled-then-os.exit(signalled+10) pattern as stoftest/
// decimaltest: a non-zero exit names the failing @test (1..N → 11..N+10).
// A failing row aborts via the assert/abort builtin (task #5 @test
// conversion).
//
// Ports ref/hare/strconv/+test/ftos_test.ha's ffmt::G / prec=void /
// fflags::NONE rows (the f64tos cases) verbatim — these are exactly
@@ -26,8 +26,6 @@ import strconv;
import os;
import math;
let signalled: i32 = 0;
fn fail() void = { os.exit(signalled + 10); };
fn streq(a: str, b: str) bool = {
if (a.len != b.len) { return false; };
@@ -56,46 +54,46 @@ fn rt64(x: f64) bool = {
// ftos_test.ha:57-64 (G/void/NONE-equivalent) — fixed-point renders.
@test fn f64tos_fixed() void = {
if (!chk(13.37, "13.37")) { fail(); };
if (!chk(12345.0, "12345")) { fail(); };
if (!chk(1100.0, "1100")) { fail(); };
if (!chk(100.0, "100")) { fail(); };
if (!chk(10.0, "10")) { fail(); };
if (!chk(1.0, "1")) { fail(); };
if (!chk(0.3, "0.3")) { fail(); };
if (!chk(0.1, "0.1")) { fail(); };
if (!chk(0.01, "0.01")) { fail(); };
if (!chk(0.011, "0.011")) { fail(); };
if (!chk(1.414, "1.414")) { fail(); };
if (!chk(-6345.972, "-6345.972")) { fail(); };
assert(!(!chk(13.37, "13.37")));
assert(!(!chk(12345.0, "12345")));
assert(!(!chk(1100.0, "1100")));
assert(!(!chk(100.0, "100")));
assert(!(!chk(10.0, "10")));
assert(!(!chk(1.0, "1")));
assert(!(!chk(0.3, "0.3")));
assert(!(!chk(0.1, "0.1")));
assert(!(!chk(0.01, "0.01")));
assert(!(!chk(0.011, "0.011")));
assert(!(!chk(1.414, "1.414")));
assert(!(!chk(-6345.972, "-6345.972")));
};
// ftos_test.ha:78-90 — scientific renders (the shortest-G E-dispatch).
@test fn f64tos_scientific() void = {
if (!chk(10000.0, "1e4")) { fail(); };
if (!chk(11000.0, "1.1e4")) { fail(); };
if (!chk(1000.0, "1e3")) { fail(); };
if (!chk(0.001, "1e-3")) { fail(); };
if (!chk(0.0011, "1.1e-3")) { fail(); };
if (!chk(0.0001, "1e-4")) { fail(); };
assert(!(!chk(10000.0, "1e4")));
assert(!(!chk(11000.0, "1.1e4")));
assert(!(!chk(1000.0, "1e3")));
assert(!(!chk(0.001, "1e-3")));
assert(!(!chk(0.0011, "1.1e-3")));
assert(!(!chk(0.0001, "1e-4")));
// dp=-2 < -1 → G dispatches to E (ftos_test.ha:62 is the ffmt::F row;
// shortest-G of 0.0031415 is scientific).
if (!chk(0.0031415, "3.1415e-3")) { fail(); };
assert(!(!chk(0.0031415, "3.1415e-3")));
};
// ftos_test.ha:12/16/27 — zero, ±infinity, nan.
@test fn f64tos_special() void = {
if (!chk(0.0, "0")) { fail(); };
assert(!(!chk(0.0, "0")));
// sign bit via (1u64 << 63), not the 0x8000000000000000 literal:
// wwstage mis-emits the I64_MIN-magnitude literal (#144 family).
let negzero: f64 = math.f64frombits(1u64 << 63u64);
if (!chk(negzero, "-0")) { fail(); };
assert(!(!chk(negzero, "-0")));
let inf: f64 = math.f64frombits(0x7FF0000000000000u64);
if (!chk(inf, "infinity")) { fail(); };
assert(!(!chk(inf, "infinity")));
let ninf: f64 = math.f64frombits(0xFFF0000000000000u64);
if (!chk(ninf, "-infinity")) { fail(); };
assert(!(!chk(ninf, "-infinity")));
let nan: f64 = math.f64frombits(0x7FF8000000000000u64);
if (!chk(nan, "nan")) { fail(); };
assert(!(!chk(nan, "nan")));
};
fn chkf32(n: f32, want: str) bool = {
@@ -106,32 +104,32 @@ fn chkf32(n: f32, want: str) bool = {
// fixed-point renders. 1.0/1.5/0.1/100/0.5 are the fold-5a probe's 5/5
// value-validated f32todecf32 pairs.
@test fn f32tos_fixed() void = {
if (!chkf32(13.37f32, "13.37")) { fail(); };
if (!chkf32(-13.37f32, "-13.37")) { fail(); }; // sign prefix + encode_f at o=1
assert(!(!chkf32(13.37f32, "13.37")));
assert(!(!chkf32(-13.37f32, "-13.37"))); // sign prefix + encode_f at o=1
// 2^25: the smallest f32 with e2 >= 0 (q == 0) — the ONLY runtime cover
// of f32todecf32's e2>=0 / q<=9 trailing-zero block (the f32-specific
// `q <= 9` + pow5multiple32 arm). External shortest-round-trip check.
if (!chkf32(33554432.0f32, "33554432")) { fail(); };
if (!chkf32(12345.0f32, "12345")) { fail(); };
if (!chkf32(1100.0f32, "1100")) { fail(); };
if (!chkf32(100.0f32, "100")) { fail(); };
if (!chkf32(10.0f32, "10")) { fail(); };
if (!chkf32(1.0f32, "1")) { fail(); };
if (!chkf32(1.5f32, "1.5")) { fail(); };
if (!chkf32(0.5f32, "0.5")) { fail(); };
if (!chkf32(0.1f32, "0.1")) { fail(); };
if (!chkf32(0.01f32, "0.01")) { fail(); };
if (!chkf32(0.011f32, "0.011")) { fail(); };
assert(!(!chkf32(33554432.0f32, "33554432")));
assert(!(!chkf32(12345.0f32, "12345")));
assert(!(!chkf32(1100.0f32, "1100")));
assert(!(!chkf32(100.0f32, "100")));
assert(!(!chkf32(10.0f32, "10")));
assert(!(!chkf32(1.0f32, "1")));
assert(!(!chkf32(1.5f32, "1.5")));
assert(!(!chkf32(0.5f32, "0.5")));
assert(!(!chkf32(0.1f32, "0.1")));
assert(!(!chkf32(0.01f32, "0.01")));
assert(!(!chkf32(0.011f32, "0.011")));
};
// ftos_test.ha tcs G/void rows — scientific (shortest-G E-dispatch).
@test fn f32tos_scientific() void = {
if (!chkf32(10000.0f32, "1e4")) { fail(); };
if (!chkf32(11000.0f32, "1.1e4")) { fail(); };
if (!chkf32(1000.0f32, "1e3")) { fail(); };
if (!chkf32(0.001f32, "1e-3")) { fail(); };
if (!chkf32(0.0011f32, "1.1e-3")) { fail(); };
if (!chkf32(0.0001f32, "1e-4")) { fail(); };
assert(!(!chkf32(10000.0f32, "1e4")));
assert(!(!chkf32(11000.0f32, "1.1e4")));
assert(!(!chkf32(1000.0f32, "1e3")));
assert(!(!chkf32(0.001f32, "1e-3")));
assert(!(!chkf32(0.0011f32, "1.1e-3")));
assert(!(!chkf32(0.0001f32, "1e-4")));
};
// ftos_test.ha:218-221 (tcsf32) — the f32-EXCLUSIVE denormal/min-normal/
@@ -140,26 +138,26 @@ fn chkf32(n: f32, want: str) bool = {
// IEEE-754 bit patterns (ww math has no F32_MIN_*/MAX_NORMAL const).
@test fn f32tos_extremes() void = {
let minsub: f32 = math.f32frombits(1u32); // 2^-149
if (!chkf32(minsub, "1e-45")) { fail(); };
assert(!(!chkf32(minsub, "1e-45")));
let minnorm: f32 = math.f32frombits(0x00800000u32); // 2^-126
if (!chkf32(minnorm, "1.1754944e-38")) { fail(); };
assert(!(!chkf32(minnorm, "1.1754944e-38")));
let maxnorm: f32 = math.f32frombits(0x7F7FFFFFu32);
if (!chkf32(maxnorm, "3.4028235e38")) { fail(); };
assert(!(!chkf32(maxnorm, "3.4028235e38")));
};
// ftos_test.ha:11/15/26 — zero, ±infinity, nan (f32 bit patterns).
@test fn f32tos_special() void = {
if (!chkf32(0.0f32, "0")) { fail(); };
assert(!(!chkf32(0.0f32, "0")));
// sign bit via (1u32 << 31), mirroring the f64 test's I64_MIN-literal
// avoidance (#144 family).
let negzero: f32 = math.f32frombits(1u32 << 31u32);
if (!chkf32(negzero, "-0")) { fail(); };
assert(!(!chkf32(negzero, "-0")));
let inf: f32 = math.f32frombits(0x7F800000u32);
if (!chkf32(inf, "infinity")) { fail(); };
assert(!(!chkf32(inf, "infinity")));
let ninf: f32 = math.f32frombits(0xFF800000u32);
if (!chkf32(ninf, "-infinity")) { fail(); };
assert(!(!chkf32(ninf, "-infinity")));
let nan: f32 = math.f32frombits(0x7FC00000u32);
if (!chkf32(nan, "nan")) { fail(); };
assert(!(!chkf32(nan, "nan")));
};
// ftos_test.ha:196-204 (tcsf64) — Hare's f64-exclusive extremes, here as a
@@ -169,23 +167,23 @@ fn chkf32(n: f32, want: str) bool = {
// via f64frombits (ww math has no F64_MIN_*/MAX_NORMAL const); exact and
// 17-digit-halfway values as literals.
@test fn f64_roundtrip() void = {
if (!rt64(9007199254740991.0)) { fail(); }; // 2^53-1
if (!rt64(90071992547409915.0)) { fail(); }; // 17-digit halfway pair
if (!rt64(90071992547409925.0)) { fail(); };
if (!rt64(math.f64frombits(0x0000000000000001u64))) { fail(); }; // F64_MIN_SUBNORMAL (5e-324)
if (!rt64(math.f64frombits(0x0010000000000000u64))) { fail(); }; // F64_MIN_NORMAL
if (!rt64(math.f64frombits(0x7FEFFFFFFFFFFFFFu64))) { fail(); }; // F64_MAX_NORMAL
assert(!(!rt64(9007199254740991.0))); // 2^53-1
assert(!(!rt64(90071992547409915.0))); // 17-digit halfway pair
assert(!(!rt64(90071992547409925.0)));
assert(!(!rt64(math.f64frombits(0x0000000000000001u64)))); // F64_MIN_SUBNORMAL (5e-324)
assert(!(!rt64(math.f64frombits(0x0010000000000000u64)))); // F64_MIN_NORMAL
assert(!(!rt64(math.f64frombits(0x7FEFFFFFFFFFFFFFu64)))); // F64_MAX_NORMAL
};
export fn main() i32 = {
signalled = 1; f64tos_fixed();
signalled = 2; f64tos_scientific();
signalled = 3; f64tos_special();
signalled = 4; f32tos_fixed();
signalled = 5; f32tos_scientific();
signalled = 6; f32tos_extremes();
signalled = 7; f32tos_special();
signalled = 8; f64_roundtrip();
f64tos_fixed();
f64tos_scientific();
f64tos_special();
f32tos_fixed();
f32tos_scientific();
f32tos_extremes();
f32tos_special();
f64_roundtrip();
os.exit(0);
return 0;
};

View File

@@ -1,15 +1,14 @@
// inttest — exercises lib/strconv integer parse: parseint / stoi64 /
// stou64 / the iN/uN width wrappers. Run with
// `out/bin/ww run lib/strconv/test/inttest.ww`. Same
// signalled-then-fail()-with-+10 pattern as decimaltest / bytestest:
// a non-zero exit code (signalled+10) pinpoints the failing case.
// `out/bin/ww run lib/strconv/test/inttest.ww`. A failing row aborts via
// the assert/abort builtin (task #5 @test conversion).
//
// Verbatim port of ref/hare/strconv/stoi.ha:56-86 (stoi/stoi_bases) and
// stou.ha:116-138 (stou/stou_bases). Hare's strconv integer tests are
// flat assert SEQUENCES, not row-array tables — mirrored here as inline
// per-case checks (feedback_test_match_hare_source: inline @test-fn for
// verbatim ports). Each case sets `signalled` first so a failure's exit
// code identifies the exact assertion.
// verbatim ports). The leading id arg to each check helper is retained
// to keep the rows 1:1 but is now inert (signalled plumbing removed, task #5).
//
// Lives in lib/strconv/test/ (not lib/strconv/) so `import strconv`
// resolves to the lib/strconv DIRECTORY (pulls the full package), not
@@ -22,124 +21,108 @@
package strconv_test;
import strconv;
import os;
let signalled: i32 = 0;
fn fail() void = { os.exit(signalled + 10); };
fn cki(id: i32, s: str, b: base, want: i64) void = {
signalled = id;
match (stoi64(s, b)) {
case let v: i64 => if (v != want) { fail(); };
case let e: invalid => fail();
case let e: overflow => fail();
case let v: i64 => assert(!(v != want));
case let e: invalid => abort();
case let e: overflow => abort();
};
};
fn cki_inv(id: i32, s: str, b: base, idx: i32) void = {
signalled = id;
match (stoi64(s, b)) {
case let v: i64 => fail();
case let e: invalid => if (e: i32 != idx) { fail(); };
case let e: overflow => fail();
case let v: i64 => abort();
case let e: invalid => assert(!(e: i32 != idx));
case let e: overflow => abort();
};
};
fn cki_ovf(id: i32, s: str, b: base) void = {
signalled = id;
match (stoi64(s, b)) {
case let v: i64 => fail();
case let e: invalid => fail();
case let v: i64 => abort();
case let e: invalid => abort();
case let e: overflow => { };
};
};
fn cku(id: i32, s: str, b: base, want: u64) void = {
signalled = id;
match (stou64(s, b)) {
case let v: u64 => if (v != want) { fail(); };
case let e: invalid => fail();
case let e: overflow => fail();
case let v: u64 => assert(!(v != want));
case let e: invalid => abort();
case let e: overflow => abort();
};
};
fn cku_inv(id: i32, s: str, b: base, idx: i32) void = {
signalled = id;
match (stou64(s, b)) {
case let v: u64 => fail();
case let e: invalid => if (e: i32 != idx) { fail(); };
case let e: overflow => fail();
case let v: u64 => abort();
case let e: invalid => assert(!(e: i32 != idx));
case let e: overflow => abort();
};
};
fn cku_ovf(id: i32, s: str, b: base) void = {
signalled = id;
match (stou64(s, b)) {
case let v: u64 => fail();
case let e: invalid => fail();
case let v: u64 => abort();
case let e: invalid => abort();
case let e: overflow => { };
};
};
fn cki32_ovf(id: i32, s: str, b: base) void = {
signalled = id;
match (stoi32(s, b)) {
case let v: i32 => fail();
case let e: invalid => fail();
case let v: i32 => abort();
case let e: invalid => abort();
case let e: overflow => { };
};
};
fn cki32(id: i32, s: str, b: base, want: i32) void = {
signalled = id;
match (stoi32(s, b)) {
case let v: i32 => if (v != want) { fail(); };
case let e: invalid => fail();
case let e: overflow => fail();
case let v: i32 => assert(!(v != want));
case let e: invalid => abort();
case let e: overflow => abort();
};
};
fn ck_int(id: i32, s: str, b: base, want: int) void = {
signalled = id;
match (stoi(s, b)) {
case let v: int => if (v != want) { fail(); };
case let e: invalid => fail();
case let e: overflow => fail();
case let v: int => assert(!(v != want));
case let e: invalid => abort();
case let e: overflow => abort();
};
};
fn ck_uint(id: i32, s: str, b: base, want: uint) void = {
signalled = id;
match (stou(s, b)) {
case let v: uint => if (v != want) { fail(); };
case let e: invalid => fail();
case let e: overflow => fail();
case let v: uint => assert(!(v != want));
case let e: invalid => abort();
case let e: overflow => abort();
};
};
fn ck_size(id: i32, s: str, b: base, want: size) void = {
signalled = id;
match (stoz(s, b)) {
case let v: size => if (v != want) { fail(); };
case let e: invalid => fail();
case let e: overflow => fail();
case let v: size => assert(!(v != want));
case let e: invalid => abort();
case let e: overflow => abort();
};
};
fn ck_int_ovf(id: i32, s: str, b: base) void = {
signalled = id;
match (stoi(s, b)) {
case let v: int => fail();
case let e: invalid => fail();
case let v: int => abort();
case let e: invalid => abort();
case let e: overflow => { };
};
};
fn ck_uint_ovf(id: i32, s: str, b: base) void = {
signalled = id;
match (stou(s, b)) {
case let v: uint => fail();
case let e: invalid => fail();
case let v: uint => abort();
case let e: invalid => abort();
case let e: overflow => { };
};
};
@@ -251,8 +234,7 @@ fn streq(a: str, b: str) bool = {
};
fn cks(id: i32, got: str, want: str) void = {
signalled = id;
if (!streq(got, want)) { fail(); };
assert(!(!streq(got, want)));
};
// ref/hare/strconv/utos.ha:74-83.

View File

@@ -1,7 +1,6 @@
// stoftest — exercises lib/strconv/stof.ww (Hare stof.ha port).
// Run with `out/bin/ww run lib/strconv/test/stoftest.ww`. Same
// signalled-then-os.exit(signalled+10) pattern as decimaltest: a
// non-zero exit names the failing @test (1..N → exit 11..N+10).
// Run with `out/bin/ww run lib/strconv/test/stoftest.ww`. A failing row
// aborts via the assert/abort builtin (task #5 @test conversion).
//
// Ports ref/hare/strconv/stof.ha's @test vectors (stof64 / stof32 /
// stofhex). Comparisons are BIT-level (math.f64bits / f32bits) so a
@@ -18,11 +17,8 @@
package strconv_test;
import strconv;
import os;
import math;
let signalled: i32 = 0;
fn fail() void = { os.exit(signalled + 10); };
// ---- unwrap helpers (bit-exact value checks) -------------------------
@@ -108,20 +104,20 @@ fn nan32(s: str) bool = {
let nzero: f64 = math.f64frombits(1u64 << 63u64); // -0.0 (1<<63 dodges the I64_MIN-literal emit bug #144)
let subn: f64 = math.f64frombits(0x0000000000000001u64); // 5e-324
if (!chk64("0", base.DEC, 0.0)) { fail(); };
if (!chk64("200", base.DEC, 200.0)) { fail(); };
if (!chk64("12345", base.DEC, 12345.0)) { fail(); };
if (!chk64("+112233445566778899", base.DEC, 1.122334455667789e17)) { fail(); };
if (!chk64("3.14", base.DEC, 3.14)) { fail(); };
if (!chk64("2.99792458E+8", base.DEC, 299792458.0)) { fail(); };
if (!chk64("6.022e23", base.DEC, 6.022e23)) { fail(); };
if (!ovf64("1e310", base.DEC)) { fail(); };
if (!chk64("9007199254740991", base.DEC, 9007199254740991.0)) { fail(); };
if (!chk64("90071992547409915", base.DEC, 90071992547409920.0)) { fail(); };
if (!chk64("90071992547409925", base.DEC, 90071992547409920.0)) { fail(); };
if (!chk64("2.2250738585072014e-308", base.DEC, 2.2250738585072014e-308)) { fail(); };
if (!chk64("-1e-324", base.DEC, nzero)) { fail(); };
if (!chk64("5e-324", base.DEC, subn)) { fail(); };
assert(!(!chk64("0", base.DEC, 0.0)));
assert(!(!chk64("200", base.DEC, 200.0)));
assert(!(!chk64("12345", base.DEC, 12345.0)));
assert(!(!chk64("+112233445566778899", base.DEC, 1.122334455667789e17)));
assert(!(!chk64("3.14", base.DEC, 3.14)));
assert(!(!chk64("2.99792458E+8", base.DEC, 299792458.0)));
assert(!(!chk64("6.022e23", base.DEC, 6.022e23)));
assert(!(!ovf64("1e310", base.DEC)));
assert(!(!chk64("9007199254740991", base.DEC, 9007199254740991.0)));
assert(!(!chk64("90071992547409915", base.DEC, 90071992547409920.0)));
assert(!(!chk64("90071992547409925", base.DEC, 90071992547409920.0)));
assert(!(!chk64("2.2250738585072014e-308", base.DEC, 2.2250738585072014e-308)));
assert(!(!chk64("-1e-324", base.DEC, nzero)));
assert(!(!chk64("5e-324", base.DEC, subn)));
// Decimal-engine edge probes migrated here when the white-box
// decimaltest.ww retired (#16): the external-test idiom can't reach
@@ -132,23 +128,23 @@ fn nan32(s: str) bool = {
// Micro-gap (rule-7, honest): decimal_shift's k=0 early-return no-op
// is a trivial guard, not reached transitively by any slow-path input
// — consciously un-migrated, not silently dropped.
if (!chk64("9999999999999999", base.DEC, 1.0e16)) { fail(); };
if (!chk64("100000000000000000001", base.DEC, 1.0e20)) { fail(); };
assert(!(!chk64("9999999999999999", base.DEC, 1.0e16)));
assert(!(!chk64("100000000000000000001", base.DEC, 1.0e20)));
if (inv64("") != 0) { fail(); };
if (inv64("0ZO") != 1) { fail(); };
if (inv64("1.23ezz") != 5) { fail(); };
assert(!(inv64("") != 0));
assert(!(inv64("0ZO") != 1));
assert(!(inv64("1.23ezz") != 5));
if (!chk64("Infinity", base.DEC, inf)) { fail(); };
if (!chk64("+Infinity", base.DEC, inf)) { fail(); };
if (!chk64("-Infinity", base.DEC, ninf)) { fail(); };
if (!chk64("infinity", base.DEC, inf)) { fail(); };
if (!chk64("inFinIty", base.DEC, inf)) { fail(); };
if (!chk64("-infinity", base.DEC, ninf)) { fail(); };
if (!chk64("-infiNity", base.DEC, ninf)) { fail(); };
if (!nan64("NaN")) { fail(); };
if (!nan64("nan")) { fail(); };
if (!nan64("naN")) { fail(); };
assert(!(!chk64("Infinity", base.DEC, inf)));
assert(!(!chk64("+Infinity", base.DEC, inf)));
assert(!(!chk64("-Infinity", base.DEC, ninf)));
assert(!(!chk64("infinity", base.DEC, inf)));
assert(!(!chk64("inFinIty", base.DEC, inf)));
assert(!(!chk64("-infinity", base.DEC, ninf)));
assert(!(!chk64("-infiNity", base.DEC, ninf)));
assert(!(!nan64("NaN")));
assert(!(!nan64("nan")));
assert(!(!nan64("naN")));
};
// ---- stof32 ----------------------------------------------------------
@@ -160,34 +156,34 @@ fn nan32(s: str) bool = {
let nzero: f32 = math.f32frombits(0x80000000u32); // -0.0
let subn: f32 = math.f32frombits(0x00000001u32); // 1e-45
if (!chk32("0", base.DEC, 0.0f32)) { fail(); };
if (!chk32("1e10", base.DEC, 1.0e10f32)) { fail(); };
if (!chk32("299792458", base.DEC, 299792458.0f32)) { fail(); };
if (!chk32("6.022e23", base.DEC, 6.022e23f32)) { fail(); };
if (!ovf32("1e40", base.DEC)) { fail(); };
if (!chk32("16777215", base.DEC, 16777215.0f32)) { fail(); };
if (!chk32("167772155", base.DEC, 167772160.0f32)) { fail(); };
if (!chk32("167772145", base.DEC, 167772140.0f32)) { fail(); };
if (!chk32("6.62607015e-34", base.DEC, 6.62607015e-34f32)) { fail(); };
if (!chk32("1.1754944e-38", base.DEC, 1.1754944e-38f32)) { fail(); };
if (!chk32("-1e-50", base.DEC, nzero)) { fail(); };
if (!chk32("1e-45", base.DEC, subn)) { fail(); };
assert(!(!chk32("0", base.DEC, 0.0f32)));
assert(!(!chk32("1e10", base.DEC, 1.0e10f32)));
assert(!(!chk32("299792458", base.DEC, 299792458.0f32)));
assert(!(!chk32("6.022e23", base.DEC, 6.022e23f32)));
assert(!(!ovf32("1e40", base.DEC)));
assert(!(!chk32("16777215", base.DEC, 16777215.0f32)));
assert(!(!chk32("167772155", base.DEC, 167772160.0f32)));
assert(!(!chk32("167772145", base.DEC, 167772140.0f32)));
assert(!(!chk32("6.62607015e-34", base.DEC, 6.62607015e-34f32)));
assert(!(!chk32("1.1754944e-38", base.DEC, 1.1754944e-38f32)));
assert(!(!chk32("-1e-50", base.DEC, nzero)));
assert(!(!chk32("1e-45", base.DEC, subn)));
if (inv32("") != 0) { fail(); };
if (inv32("0ZO") != 1) { fail(); };
if (inv32("1.23e-zz") != 6) { fail(); };
assert(!(inv32("") != 0));
assert(!(inv32("0ZO") != 1));
assert(!(inv32("1.23e-zz") != 6));
if (!chk32("Infinity", base.DEC, inf)) { fail(); };
if (!chk32("+Infinity", base.DEC, inf)) { fail(); };
if (!chk32("-Infinity", base.DEC, ninf)) { fail(); };
if (!chk32("infinity", base.DEC, inf)) { fail(); };
if (!chk32("inFinIty", base.DEC, inf)) { fail(); };
if (!chk32("-infinity", base.DEC, ninf)) { fail(); };
if (!chk32("-infiniTy", base.DEC, ninf)) { fail(); };
if (!nan32("NaN")) { fail(); };
if (!nan32("nan")) { fail(); };
if (!nan32("naN")) { fail(); };
if (!chk32("9.19100241453305036800e+20", base.DEC, 9.19100241453305036800e+20f32)) { fail(); };
assert(!(!chk32("Infinity", base.DEC, inf)));
assert(!(!chk32("+Infinity", base.DEC, inf)));
assert(!(!chk32("-Infinity", base.DEC, ninf)));
assert(!(!chk32("infinity", base.DEC, inf)));
assert(!(!chk32("inFinIty", base.DEC, inf)));
assert(!(!chk32("-infinity", base.DEC, ninf)));
assert(!(!chk32("-infiniTy", base.DEC, ninf)));
assert(!(!nan32("NaN")));
assert(!(!nan32("nan")));
assert(!(!nan32("naN")));
assert(!(!chk32("9.19100241453305036800e+20", base.DEC, 9.19100241453305036800e+20f32)));
};
// ---- stofhex ---------------------------------------------------------
@@ -196,44 +192,44 @@ fn nan32(s: str) bool = {
// has no hex-float literal lexer / no F*_MAX_NORMAL math consts.
@test fn stof64_hex() void = {
if (!chk64("0p0", base.HEX, 0.0)) { fail(); };
if (!chk64("1p0", base.HEX, 1.0)) { fail(); };
if (!chk64("-1p0", base.HEX_LOWER, -1.0)) { fail(); };
assert(!(!chk64("0p0", base.HEX, 0.0)));
assert(!(!chk64("1p0", base.HEX, 1.0)));
assert(!(!chk64("-1p0", base.HEX_LOWER, -1.0)));
// 0x1.fp-2 = 1.9375 * 2^-2 = 0.484375 (exact).
if (!chk64("1.fp-2", base.HEX, 0.484375)) { fail(); };
assert(!(!chk64("1.fp-2", base.HEX, 0.484375)));
// F64_MAX_NORMAL.
if (!chk64("1.fffffffffffffp+1023", base.HEX,
math.f64frombits(0x7FEFFFFFFFFFFFFFu64))) { fail(); };
math.f64frombits(0x7FEFFFFFFFFFFFFFu64))) { abort(); };
// F64_MIN_NORMAL.
if (!chk64("1.0000000000000p-1022", base.HEX,
math.f64frombits(0x0010000000000000u64))) { fail(); };
math.f64frombits(0x0010000000000000u64))) { abort(); };
// F64_MIN_SUBNORMAL.
if (!chk64("0.0000000000001p-1022", base.HEX,
math.f64frombits(0x0000000000000001u64))) { fail(); };
if (!ovf64("1p+1024", base.HEX)) { fail(); };
if (!chk64("0.00000000000001p-1022", base.HEX, 0.0)) { fail(); };
math.f64frombits(0x0000000000000001u64))) { abort(); };
assert(!(!ovf64("1p+1024", base.HEX)));
assert(!(!chk64("0.00000000000001p-1022", base.HEX, 0.0)));
};
@test fn stof32_hex() void = {
if (!chk32("0p0", base.HEX, 0.0f32)) { fail(); };
if (!chk32("1p0", base.HEX, 1.0f32)) { fail(); };
if (!chk32("-1p0", base.HEX, -1.0f32)) { fail(); };
if (!chk32("1.fp-2", base.HEX, 0.484375f32)) { fail(); };
assert(!(!chk32("0p0", base.HEX, 0.0f32)));
assert(!(!chk32("1p0", base.HEX, 1.0f32)));
assert(!(!chk32("-1p0", base.HEX, -1.0f32)));
assert(!(!chk32("1.fp-2", base.HEX, 0.484375f32)));
// F32_MAX_NORMAL.
if (!chk32("1.fffffd586b834p+127", base.HEX,
math.f32frombits(0x7F7FFFFFu32))) { fail(); };
math.f32frombits(0x7F7FFFFFu32))) { abort(); };
// F32_MIN_NORMAL.
if (!chk32("1.0p-126", base.HEX, math.f32frombits(0x00800000u32))) { fail(); };
assert(!(!chk32("1.0p-126", base.HEX, math.f32frombits(0x00800000u32))));
// F32_MIN_SUBNORMAL.
if (!chk32("1.6p-150", base.HEX, math.f32frombits(0x00000001u32))) { fail(); };
if (!ovf32("1.0p+128", base.HEX)) { fail(); };
if (!chk32("1.0p-151", base.HEX, 0.0f32)) { fail(); };
assert(!(!chk32("1.6p-150", base.HEX, math.f32frombits(0x00000001u32))));
assert(!(!ovf32("1.0p+128", base.HEX)));
assert(!(!chk32("1.0p-151", base.HEX, 0.0f32)));
};
export fn main() i32 = {
signalled = 1; stof64_dec();
signalled = 2; stof32_dec();
signalled = 3; stof64_hex();
signalled = 4; stof32_hex();
stof64_dec();
stof32_dec();
stof64_hex();
stof32_hex();
return 0;
};