aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/DFLOAT.ht
blob: c1c2120f51a18169486a9a5055e0868e85e006d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\DoubleFloatXmpTitle}{DoubleFloat}
\newcommand{\DoubleFloatXmpNumber}{9.17}
%
% =====================================================================
\begin{page}{DoubleFloatXmpPage}{9.17 DoubleFloat}
% =====================================================================
\beginscroll
%

\Language{} provides two kinds of floating point numbers.
The domain \spadtype{Float} (abbreviation \spadtype{FLOAT})
implements a model of arbitrary
%-% \HDindex{floating point!arbitrary precision}{DoubleFloatXmpPage}{9.17}{DoubleFloat}
precision floating point numbers.
%-% \HDexptypeindex{Float}{DoubleFloatXmpPage}{9.17}{DoubleFloat}
The domain \spadtype{DoubleFloat} (abbreviation \spadtype{DFLOAT})
is intended to make available
%-% \HDindex{floating point!hardware}{DoubleFloatXmpPage}{9.17}{DoubleFloat}
hardware floating point arithmetic in \Language{}.
The actual model of floating point \spadtype{DoubleFloat} that provides is
system-dependent.
For example, on the IBM system 370 \Language{} 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
\spadtype{DoubleFloat}.
Use \spadsys{)show DoubleFloat} to get a list of operations or
the \HyperName{} \Browse{} facility to get more extensive
documentation about \spadtype{DoubleFloat}.

\xtc{
By default, floating point numbers that you enter into \Language{}
are of type \spadtype{Float}.
}{
\spadpaste{2.71828}
}
You must therefore tell \Language{} that you want to use
\spadtype{DoubleFloat} values and operations.
The following are some conservative guidelines for getting
\Language{} to use \spadtype{DoubleFloat}.

\xtc{
To get a value of type \spadtype{DoubleFloat}, use a target with
\spadSyntax{@}, \ldots
}{
\spadpaste{2.71828@DoubleFloat}
}
\xtc{
a conversion, \ldots
}{
\spadpaste{2.71828 :: DoubleFloat}
}
\xtc{
or an assignment to a declared variable.
It is more efficient if you use a target rather than an explicit or
implicit conversion.
}{
\spadpaste{eApprox : DoubleFloat := 2.71828 \bound{eApprox}}
}

\xtc{
You also need to declare functions that work with
\spadtype{DoubleFloat}.
}{
\spadpaste{avg : List DoubleFloat -> DoubleFloat \bound{avgDec}}
}
\xtc{
}{
\begin{spadsrc}[\bound{avg}\free{avgDec}]
avg l ==
  empty? l => 0 :: DoubleFloat
  reduce(_+,l) / #l
\end{spadsrc}
}
\xtc{
}{
\spadpaste{avg [] \free{avg}}
}
\xtc{
}{
\spadpaste{avg [3.4,9.7,-6.8] \free{avg}}
}
\xtc{
Use package-calling for operations from \spadtype{DoubleFloat} unless
the arguments themselves are already of type \spadtype{DoubleFloat}.
}{
\spadpaste{cos(3.1415926)\$DoubleFloat}
}
\xtc{
}{
\spadpaste{cos(3.1415926 :: DoubleFloat)}
}

By far, the most common usage of \spadtype{DoubleFloat} is for functions
to be graphed.
For more information about \Language{}'s numerical and graphical
facilities, see
\downlink{``\ugGraphTitle''}{ugGraphPage} in Section \ugGraphNumber\ignore{ugGraph},
\downlink{``\ugProblemNumericTitle''}{ugProblemNumericPage} in Section \ugProblemNumericNumber\ignore{ugProblemNumeric}, and
\downlink{`Float'}{FloatXmpPage}\ignore{Float}.
\endscroll
\autobuttons
\end{page}
%