testfloat - Maple Help

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 $3x+2$, and the actual computed result is $ax+b$, 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, , ulps], where  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 $bx+c$ (that is, the polynomial is expressed as a sum of powers of $bx+c$), 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

 > $\mathrm{Digits}≔3:$
 > $\mathrm{testfloat}\left(1.23,1.25,2\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{testfloat}\left(1.23,1.25,1\right)$
 $\left[{\mathrm{false}}{,}{2.}{,}{\mathrm{ulps}}\right]$ (2)
 > $\mathrm{testfloat}\left(\left[1.23,3.45+6.78I\right],\left[1.22+0.0001I,3.46+6.76I\right],2\right)$
 $\left[{\mathrm{true}}{,}{\mathrm{true}}\right]$ (3)
 > $\mathrm{testfloat}\left(\left[1.23,3.45+6.78I\right],\left[1.22+0.0001I,3.46+6.76I\right],2,\mathrm{model}=2\right)$
 $\left[\left[{\mathrm{true}}{,}\left[{\mathrm{false}}{,}{100.}{,}{\mathrm{ulps}}\right]\right]{,}\left[{\mathrm{true}}{,}{\mathrm{true}}\right]\right]$ (4)
 > $\mathrm{series}\left(\mathrm{exp}\left(x\right),x=0.123,3\right)$
 ${1.13}{+}{1.13}{}\left({x}{-}{0.123}\right){+}{0.565}{}{\left({x}{-}{0.123}\right)}^{{2}}{+}{O}{}\left({\left({x}{-}{0.123}\right)}^{{3}}\right)$ (5)
 > $\mathrm{testfloat}\left(,\mathrm{series}\left(1.23+1.13\left(x-0.123\right)+0.567{\left(x-0.123\right)}^{2}+\mathrm{O}\left({\left(x-0.123\right)}^{3}\right),x=0.123,3\right),1\right)$
 $\left[\left[{\mathrm{false}}{,}{10.}{,}{\mathrm{ulps}}\right]{,}{\mathrm{true}}{,}{\mathrm{true}}{,}{\mathrm{true}}{,}\left[{\mathrm{false}}{,}{2.}{,}{\mathrm{ulps}}\right]{,}{\mathrm{true}}{,}{\mathrm{true}}{,}{\mathrm{true}}{,}{\mathrm{true}}\right]$ (6)
 > $\mathrm{testfloat}\left(\left[x=0.00001,y=0.025\right],\left[x=0.00099,y=0.010\right],1,\mathrm{digits}=2,\mathrm{test}=2\right)$
 $\left[{\mathrm{true}}{,}\left[{\mathrm{false}}{,}{1.5}{,}{\mathrm{ulps}}\right]\right]$ (7)
 > $\mathrm{testfloat}\left(12.3..45.6,12.6..45.5,5\right)$
 $\left[{\mathrm{true}}{,}{\mathrm{true}}\right]$ (8)