testfloat - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


testfloat

compare expressions involving floating-point numbers

 

Calling Sequence

Parameters

Description

Examples

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, <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 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

Digits3&colon;

testfloat1.23&comma;1.25&comma;2

true

(1)

testfloat1.23&comma;1.25&comma;1

false&comma;2.&comma;ulps

(2)

testfloat1.23&comma;3.45+6.78I&comma;1.22+0.0001I&comma;3.46+6.76I&comma;2

true&comma;true

(3)

testfloat1.23&comma;3.45+6.78I&comma;1.22+0.0001I&comma;3.46+6.76I&comma;2&comma;model=2

true&comma;false&comma;100.&comma;ulps &comma;true&comma;true

(4)

seriesexpx&comma;x=0.123&comma;3

1.13+1.13x0.123+0.565x0.1232+Ox0.1233

(5)

testfloat&comma;series1.23+1.13x0.123+0.567x0.1232+Ox0.1233&comma;x=0.123&comma;3&comma;1

false&comma;10.&comma;ulps &comma;true&comma;true&comma;true&comma;false&comma;2.&comma;ulps &comma;true&comma;true&comma;true&comma;true

(6)

testfloatx=0.00001&comma;y=0.025&comma;x=0.00099&comma;y=0.010&comma;1&comma;digits=2&comma;test=2

true&comma;false&comma;1.5&comma;ulps

(7)

testfloat12.3..45.6&comma;12.6..45.5&comma;5

true&comma;true

(8)

See Also

comparray

Digits

fnormal

series