Section9.17

]>
Book Contents Previous Section 9.16 DistributedMultivariatePolynomial Next Section 9.18 EqTable Book Index

## 9.17 DoubleFloat

Axiom provides two kinds of floating point numbers. The domain Float (abbreviation FLOAT) implements a model of arbitrary precision floating point numbers. The domain DoubleFloat (abbreviation DFLOAT) is intended to make available hardware floating point arithmetic in Axiom. The actual model of floating point DoubleFloat that provides is system-dependent. For example, on the IBM system 370 Axiom uses IBM double precision which has fourteen hexadecimal digits of precision or roughly sixteen decimal digits. Arbitrary precision floats allow the user to specify the precision at which arithmetic operations are computed. Although this is an attractive facility, it comes at a cost. Arbitrary-precision floating-point arithmetic typically takes twenty to two hundred times more time than hardware floating point.

The usual arithmetic and elementary functions are available for DoubleFloat. Use )show DoubleFloat to get a list of operations or the HyperDoc browse facility to get more extensive documentation about DoubleFloat.

By default, floating point numbers that you enter into Axiom are of type Float.

2.71828

2. 71828

Type: Float

You must therefore tell Axiom that you want to use DoubleFloat values and operations. The following are some conservative guidelines for getting Axiom to use DoubleFloat.

To get a value of type DoubleFloat, use a target with @, ...

2.71828@DoubleFloat

2. 71828

Type: DoubleFloat

a conversion, ...

2.71828 :: DoubleFloat

2. 71828

Type: DoubleFloat

or an assignment to a declared variable. It is more efficient if you use a target rather than an explicit or implicit conversion.

eApprox : DoubleFloat := 2.71828

2. 71828

Type: DoubleFloat

You also need to declare functions that work with DoubleFloat.

avg : List DoubleFloat -> DoubleFloat
Type: Void
avg l ==
empty? l => 0 :: DoubleFloat
reduce(_+,l) / #l
Type: Void
avg []

this complains but succeeds

avg [3.4,9.7,-6.8]
Compiling function avg with type List Float -> DoubleFloat

2. 1

Type: DoubleFloat

Use package-calling for operations from DoubleFloat unless the arguments themselves are already of type DoubleFloat.

cos(3.1415926)$DoubleFloat

-0. 999999999999999

Type: DoubleFloat
cos(3.1415926 :: DoubleFloat)

-0. 999999999999999

Type: DoubleFloat

By far, the most common usage of DoubleFloat is for functions to be graphed. For more information about Axiom's numerical and graphical facilities, see Section ugGraph , ugProblemNumeric , and FloatXmpPage .

Book Contents Previous Section 9.16 DistributedMultivariatePolynomial Next Section 9.18 EqTable Book Index