testfloat - compare expressions involving floating-point numbers
|
Calling Sequence
|
|
testfloat(computed, correct, bound, ...)
|
|
Parameters
|
|
computed
|
-
|
test value
|
correct
|
-
|
reference value
|
bound
|
-
|
non-negative real number
|
|
|
|
|
Description
|
|
•
|
testfloat verifies that the floating-point values appearing in a computed expression are within the given bound of the reference "correct" values. For example, if the expected result of a computation is the polynomial , and the actual computed result is , then testfloat(a*x+b, 3*x+2, 5) will check to see that a is within 5 ulps (units in the last place) of 3 and b is within 5 ulps of 2.
|
•
|
The error bound is defined in terms of "units in the last place", or "ulps". Given a number x, 1 ulp relative to x is the value Float(1, -Digits+1+ilog10(x)). For more information, see ilog10.
|
•
|
The test value, computed, can be a single number (real or complex), a range whose endpoints are single numbers, or a list, series, univariate polynomial or univariate rational function over the complex or real numbers, or an equation whose right-hand side is one of these.
|
•
|
The reference value, correct, can be any of the types of expressions or values as the test value. The reference value need not be of the same type as the computed value, but it should either be 0 or, after the conversion processing described below, it should have the same number of numerics for comparison as the test value has.
|
•
|
Any parameters to testfloat after the third are assumed to be options controlling the type of test to be performed, and must be given in the form option = value. The recognized options are:
|
|
|
model
|
Determines whether complex numerics are treated as
|
|
single numbers (model=1; the default) or as pairs
|
|
of real numbers (model=2).
|
|
|
test
|
Specifies the type of test to perform: test=1 means
|
|
use a relative error test (this is the default,
|
|
unless correct=0); test=2 means use an absolute
|
|
error test (this is implied if correct=0).
|
|
|
digits
|
Specifies the value of Digits to be used when
|
|
calculating the size of a ulp; must be a positive
|
|
integer.
|
|
|
|
|
•
|
For a comparison of a single real number with a reference value (or a single complex number with a reference value and the option model=2 not given), the output will be either the single value true or the list [false, <size of error>, ulps], where <size of error> is rounded to 3 digits.
|
•
|
For tests involving more than one floating-point value in the parameter computed, the output will be a list, each of whose elements is in the above form.
|
•
|
For series comparisons, the point of expansion of the series is checked, as well as each of the coefficients.
|
•
|
For polynomial comparisons, if there is a common subexpression of the form (that is, the polynomial is expressed as a sum of powers of ), then this subexpression is first replaced by a single name. In any case, the polynomial is then converted to a series for comparison, and the values of b and c are also checked.
|
•
|
Except in the most elementary case, all expressions are converted to lists before the actual comparison is done.
|
•
|
If computed is not just a single float (or a single complex float with model=2 not given), then, after conversion to lists, the test value and the reference value lists should have the same length, or the reference value should be 0. If the reference value is not 0 and the lists do not have the same length, the shorter one will be extended by infinity, producing the corresponding output value [false, infinity, ulps].
|
•
|
If correct=0, an absolute error check is performed on each of the numerics appearing in the expression computed.
|
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
>
|
|
| (8) |
|
|