module scheme import math import strconv fn complex_near(actual f64, expected f64) bool { if actual == expected { return true } if math.is_nan(actual) || math.is_inf(actual, 0) { return false } // Relative tolerance with a subnormal absolute floor; an expected zero // cannot hide a branch residue or an entirely lost tiny component. return math.abs(actual - expected) <= math.max(math.abs(expected) * 4e-13, math.f64_from_bits(8)) } fn test_independent_fraction_and_cmath_with_r5_cut_oracles() { fixture := $embed_file('testdata/complex_cases.tsv').to_string() mut vm := new() mut count := 0 for row in fixture.split_into_lines() { if row.len == 0 || row[0] == `#` { continue } f := row.split('\t') assert f.len == 6, row value := vm.eval(f[2]) or { panic('${f[0]} ${f[2]}: ${err.msg()}') } if f[3] == 'exact' { assert write(value) or { panic(err) } == f[4], '${f[0]} ${f[2]}' assert value.tag.str() == f[5], f[0] } else { z := inexact_complex(value) or { panic(err) } r, i := strconv.atof64(f[4]) or { panic(err) }, strconv.atof64(f[5]) or { panic(err) } assert complex_near(z.re, r), '${f[0]} ${f[2]} real ${z.re} != ${r}' assert complex_near(z.im, i), '${f[0]} ${f[2]} imag ${z.im} != ${i}' } count++ } assert count == 1566 }