John R. Hauser
2017 August 18
testfloat program tests an implementation of floating-point
arithmetic for conformity to the IEEE Standard for Binary Floating-Point
testfloat is part of the Berkeley TestFloat package, a small
collection of programs for performing such tests.
For general information about TestFloat, see file
testfloat program is an all-in-one tool for testing
It generates test operand values, invokes a floating-point operation with the
generated operands, and examines the corresponding computed results, reporting
unexpected results as likely errors.
While the processes of generating inputs and examining results are generic, a
particular build of
testfloat is limited to testing only the one
implementation of floating-point it has been compiled to invoke.
For example, while one instance of
testfloat might be compiled to
execute a computer’s hardware instruction for floating-point addition, a
different version might be compiled to call a subroutine called
myAddFloat that is linked into the
To test a new implementation of floating-point (a new set of machine
instructions or a new set of subroutines), a new
testfloat must be
compiled containing the code needed to invoke the new floating-point.
The default build of
testfloat assumes that C types
/, type conversions, etc.
This tests the floating-point arithmetic seen by C programs.
Depending on the compiler and the options selected during compilation, this may
or may not be the same as the computer’s floating-point hardware, if any.
testfloat program will ordinarily test an operation for all
five rounding modes defined by the IEEE Floating-Point Standard, one after the
other, plus possibly a sixth mode, round to odd (depending on the
options selected when
testfloat was compiled).
If the rounding mode is not supposed to have any affect on the
results—for instance, some operations do not require rounding—only
the nearest/even rounding mode is checked.
For double-extended-precision operations affected by rounding precision
testfloat also tests all three rounding precision modes,
one after the other.
Testing can be limited to a single rounding mode and/or rounding precision with
appropriate command-line options.
For more about the operation of
testfloat and how to interpret its
output, refer to
testfloat program is executed as a command with this syntax:
Square brackets (testfloat [<option>...] <function>
[ ]) denote optional arguments,
<option>is a supported option, and
<function>is the name of either a testable operation or a function set. The available options and function sets are documented below. The
-listoption can be used to obtain a list of all testable operations for a given build of
testfloatis executed without any arguments, a summary of usage is written.
testfloat program accepts several command options.
If mutually contradictory options are given, the last one has priority.
-help option causes a summary of program usage to be written,
after which the program exits.
-list option causes a list of testable operations to be
written, after which the program exits.
An operation is testable by
testfloat if the program knows some
way to invoke the operation.
-seed option sets the seed for the pseudo-random number
generator used for generating test cases.
The argument to
-seed is a nonnegative integer.
Executing the same compiled
testfloat program with the same
arguments (including the same pseudo-random number seed) should always perform
the same sequence of tests, whereas changing the pseudo-random number seed
should result in a different sequence of tests.
The default seed number
-level option sets the level of testing.
The argument to
-level can be either 1
-errors option instructs
testfloat to report no
more than the specified number of errors for any combination of operation,
rounding mode, etc.
The argument to
-errors must be a nonnegative decimal integer.
Once the specified number of error reports has been generated,
testfloat ends the current test and begins the next one, if any.
The default is
testfloat to report every error it finds.
-errorstop option causes the program to exit after the first
operation for which any errors are reported.
-forever option causes a single operation to be repeatedly
Only one rounding mode and/or rounding precision can be tested in a single
If not specified, the rounding mode defaults to nearest/even.
-checkNaNs option causes
testfloat to verify the
bitwise correctness of NaN results.
In order for this option to be sensible,
testfloat must have been
compiled so that its internal reference implementation of floating-point
(Berkeley SoftFloat) generates the proper NaN results for the system being
-precision32, -precision64, -precision80
-precision32 option restricts
testing to only the cases in which the rounding precision is
-precision64 fixes the rounding precision to
-precision80 fixes the rounding precision to the full
The precision-control options may not be supported at all if no double-extended-precision operations are testable.
-rnear_even, -rnear_maxMag, -rminMag, -rmin, -rmax, -rodd
-rnear_even option restricts testing to only the cases in
which the rounding mode is nearest/even.
The other rounding mode choices are not tested.
-rnear_maxMag forces rounding to nearest/maximum
-rminMag forces rounding to minimum
magnitude (toward zero),
-rmin forces rounding to minimum (down,
toward negative infinity),
-rmax forces rounding to maximum (up,
toward positive infinity), and
-rodd, if supported, forces
rounding to odd.
These options are ignored for operations that are exact and thus do not round,
or that have the rounding mode included in the function name (such as
-tininessbefore option indicates that the floating-point
implementation being tested detects tininess on underflow before rounding.
-tininessafter option indicates that tininess is detected
testfloat program alters its expectations accordingly.
These options override the default selected when
Choosing the wrong one of these two options should cause error reports for some
(but not all) operations.
testfloat can test an operation for all five or six
rounding modes in sequence, multiple operations can be tested with a single
Two sets are recognized:
-all1 is all one-operand operations, while
-all2 is all two-operand operations.
A function set is used in place of an operation name in the
testfloat command line, such as
testfloat [<option>...] -all1