~/bend-docscommunity

FORMAT_LAWS.bend open laws/TODOs

raw source on the hub · import bend-float64@0.1.5.0/FORMAT_LAWS.bend as FORMAT_LAWS

The laws of bend-float64's fixed-digit formats (format.bend), at literal inputs; expected strings are Python's. test/format_check.py compares hundreds of thousands more with Python. Gate: ./bend-check FORMAT_PROOF.bend --verdict

3 imports
import Base
import ./float64.bend as F
import ./format.bend as FM

Laws

law fixed_values provedin FORMAT_PROOF.bendsource · line 13 · raw

{[0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1069547520, 0), 2), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1071120384, 0), 2), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1074003968, 0), 0), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(3215227617, 1202590843), 1), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(2147483648, 0), 2), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1069128089, 2576980378), 20), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(2146435072, 0), 2), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(4293918720, 0), 0), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.fixed(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(2146959360, 0), 3)] == ["0.12", "0.38", "2", "-0.0", "-0.00", "0.10000000000000000555", "inf", "-inf", "nan"] : List<&2, String>}

Guarantees: fixed is '%.nf': 0.125 and 0.375 at 2 digits tie to even (0.12, 0.38), 2.5 at 0 digits is 2 (no point), -0.04 at 1 digit keeps its sign (-0.0), -0.0 prints -0.00, 0.1 at 20 digits shows the exact binary value (0.10000000000000000555), and inf, -inf, nan print as Python prints them. Why it matters: a table written with fixed must read the same as one written by Python or NumPy; rounding halves up, or dropping the sign of a negative that rounds to zero, changes the text.

law sci_values provedin FORMAT_PROOF.bendsource · line 21 · raw

{[0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.sci(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(0, 0), 3), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.sci(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1152724212, 3878328143), 3), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.sci(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1071644672, 0), 0), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.sci(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1074003968, 0), 0), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.sci(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1079984128, 0), 1), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.sci(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1080090624, 0), 1)] == ["0.000e+00", "1.000e+23", "5e-01", "2e+00", "1.2e+02", "1.4e+02"] : List<&2, String>}

Guarantees: sci is '%.ne': 0.0 is 0.000e+00; 9.9999e22 at 3 digits rounds across a power of ten to 1.000e+23 (the exponent corrected after rounding); 0.5 and 2.5 at 0 digits are 5e-01 and 2e+00 (no point; 2.5 is exact); 125 and 135 at 1 digit are exact ties after dividing by 10 and go to even (1.2e+02, 1.4e+02). Why it matters: the exponent is found before rounding, and rounding can carry into the next decade.

law general_values provedin FORMAT_PROOF.bendsource · line 29 · raw

{[0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1076101113, 1917273401), 5), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1093850759, 0), 6), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1058682594, 3944497965), 6), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1055514876, 2945679612), 6), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1079574528, 0), 0), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(2147483648, 0), 6), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1108078734, 2952790016), 6), 0xe8796d1f170a8cd1a32ab698bd6d4d3d/format.general(0xe8796d1f170a8cd1a32ab698bd6d4d3d/float64.of_bits(1081073664, 0), 2)] == ["10", "1.23457e+06", "0.0001", "1.234e-05", "1e+02", "-0", "1.5e+10", "2.6e+02"] : List<&2, String>}

Guarantees: general is '%.ng': 9.99995 at 5 digits rounds to 10 (trailing zeros and point dropped), 1234567 at 6 switches to 1.23457e+06, 0.0001 and 1.234e-05 sit on either side of the -4 threshold, 100 at 0 digits (1 digit) is 1e+02, -0.0 is -0, 1.5e10 drops its zeros in scientific form (1.5e+10), 255 at 2 digits is 2.6e+02. Why it matters: %g chooses its form by the exponent after rounding and strips zeros; each threshold is a branch.