Test vectors

Test vectors for the float model, all in Berkeley TestFloat format and stored gzip-compressed. lake exe testfloat-check (see FloatModelTests/TestFloatCheck.lean) discovers every *.txt.gz file here, decompresses it with gzip -dc, and checks the model's binary32/binary64 operations against it. There is no on-the-fly generation: these files are the source of truth.

Each line is <operand1> [<operand2> [<operand3>]] <expected> <flags> (one operand for unary operations, two for binary ones, three for the fused multiply-add), all fields hexadecimal, floats given as their bit patterns; 16 digits for binary64, 8 for binary32. The flags field is ignored (the model computes no exception flags) and NaN results are compared as a class (the model emits a canonical NaN).

File names are <precision>_<operation> (e.g. f64_add, f32_sqrt); the subdirectory names the suite. Operations covered: add sub mul div sqrt mulAdd eq le lt. mulAdd is TestFloat's name for the fused multiply-add a * b + c; it checks Float.Model.fma/Float32.Model.fma.

Integer-to-float conversions are named <int>_to_<precision> (e.g. i64_to_f64, ui32_to_f32), with <int> one of ui32 ui64 i32 i64. These are unary: each line is <integer> <expected> <flags> with the integer operand given as its bit pattern (8 hexadecimal digits for the 32-bit types, 16 for the 64-bit types; signed types are two's complement). They check Float.Model.of{U}Int{32,64}/Float32.Model.of{U}Int{32,64}.

Float-to-integer conversions are named <precision>_to_<int> (e.g. f64_to_i32, f32_to_ui64). These are unary: each line is <float> <expected> <flags> with the float operand as its bit pattern and the integer result in the low bits (8 hexadecimal digits for the 32-bit types, 16 for the 64-bit types; signed types are two's complement). They check Float.Model.to{U}Int{32,64}/Float32.Model.to{U}Int{32,64}. Unlike the float-result files, the integer result is compared bit-for-bit and never treated as a NaN class.

These follow the saturating convention of Lean‘s native Float.toIntX/toUIntX (and LLVM’s fptosi.sat/fptoui.sat): the result is rounded toward zero (truncated), an out-of-range magnitude saturates to the destination type's min/max, and a NaN maps to zero. This differs from the x86 CVTT (“integer indefinite”) behavior that stock TestFloat emits, so these files are generated with a custom SoftFloat specialization (see below) rather than the default; they are the only files generated with -rminMag (truncation) instead of -rnear_even.

Suites

testfloat/: Berkeley TestFloat, level 1

Generated by testfloat_gen from Berkeley TestFloat (version 3e, obtain from https://www.jhauser.us/arithmetic/TestFloat.html):

testfloat_gen -level 1 -rnear_even <precision>_<operation>
testfloat_gen -level 1 -rnear_even <int>_to_<precision>
testfloat_gen -level 1 -rminMag   <precision>_to_<int>     # custom build, see below

The three-operand <precision>_mulAdd files are subsampled: level 1 emits about 6.1 million cases for a ternary operation (-n can only raise that count, never lower it), far too large to commit. Keep every 128th line, plus every triple drawn from the ten values ±0, ±1, ±∞, and one quiet and one signaling NaN of each sign. The NaN bit patterns below occur in TestFloat's systematic sequence. This retains all 1000 combinations of these values, including signed-zero and infinity combinations, while keeping the files close to the size of the other suites.

Systematic and randomized cases are interleaved throughout the stream. Sampling every 128th line visits all nine operand mixes, but shares factors with the 88-value systematic operand cycle and can omit special values. Preserve the selected triples wherever they occur, rather than relying on a prefix of the output.

Run this from test-vectors/, with testfloat_gen on PATH:

set -o pipefail
for precision in f32 f64; do
  testfloat_gen -seed 1 -level 1 -rnear_even "${precision}_mulAdd" |
    awk '
      BEGIN {
        split("00000000 80000000 3F800000 BF800000 7F800000 FF800000 " \
              "7F800001 FF800001 7FFFFFFF FFFFFFFF " \
              "0000000000000000 8000000000000000 3FF0000000000000 BFF0000000000000 " \
              "7FF0000000000000 FFF0000000000000 7FF0000000000001 FFF0000000000001 " \
              "7FFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF", values)
        for (i in values) special[values[i]] = 1
      }
      NR % 128 == 1 || ($1 in special && $2 in special && $3 in special)
    ' | gzip -n > "testfloat/${precision}_mulAdd.txt.gz"
done

These files were generated on Linux x86-64 with glibc, using TestFloat's Linux-x86_64-GCC build. The fixed seed makes generation deterministic for a given build; different C libraries can produce different randomized operands. gzip -n omits timestamps and file names from the compressed output.

The <precision>_to_<int> (float-to-integer) files use -rminMag (round toward zero) and require a testfloat_gen linked against a custom SoftFloat specialization, because the out-of-range/NaN result of a float-to-integer conversion is baked into the SoftFloat library at build time and stock SoftFloat ships the x86 CVTT convention rather than the saturating one Lean‘s native conversions use. To reproduce, copy SoftFloat’s 8086-SSE specialization to a new directory (here source/8086-SSE-satconv/) and change only the integer-conversion constants in its specialize.h to:

ui32_fromPosOverflow 0xFFFFFFFF              i32_fromPosOverflow  0x7FFFFFFF
ui32_fromNegOverflow 0                       i32_fromNegOverflow  (-0x7FFFFFFF - 1)
ui32_fromNaN         0                       i32_fromNaN          0
ui64_fromPosOverflow 0xFFFFFFFFFFFFFFFF      i64_fromPosOverflow  0x7FFFFFFFFFFFFFFF
ui64_fromNegOverflow 0                       i64_fromNegOverflow  (-0x7FFFFFFFFFFFFFFF - 1)
ui64_fromNaN         0                       i64_fromNaN          0

then build SoftFloat with make SPECIALIZE_TYPE=8086-SSE-satconv, relink testfloat_gen against the resulting softfloat.a, and generate. The arithmetic and int-to-float files are unaffected by this change and are generated with the stock build.

ucblib/: UCBTEST library vectors

The binary32/binary64 vectors shipped with the UCBTEST suite (obtain from https://netlib.org/fp/index.html) (ucb/ucblib/{add,sub,mul,div,sqrt}{s,d}.input), converted from their native format to TestFloat format: only round-to-nearest (n) rows are kept (the model implements no other rounding mode), the two 32-bit words of each binary64 value are combined into one bit pattern, and uo (“result is unordered/NaN”) rows are emitted with a canonical NaN as the expected value (10 files).

ucbtest-gen/: UCBTEST-generated hard cases

Number-theoretically hard halfway and nearly-halfway cases for multiplication, division, and square root, generated by adaptations of ucbmultest/ucbdivtest/ucbsqrtest (Kahan's constructions) that emit TestFloat-format vectors instead of testing the host arithmetic. Each emitted vector is cross-checked against correctly-rounded host arithmetic, so it is correct by construction. Default count ntests = 10000 (6 files: f32/f64 × mul/div/sqrt).

Note: f32_mul contains only a handful of vectors. The nearly-halfway multiplication construction needs intermediates wider than the 24-bit binary32 significand, so its provability check correctly declines almost all of those cases in single precision; only the small halfway set remains. (f32_div/f32_sqrt are unaffected.) Broad multiplication coverage for binary32 comes from the testfloat/ and ucblib/ suites.