File: num.tex

package info (click to toggle)
testu01 1.2.3%2Bds-2
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 17,740 kB
  • ctags: 4,799
  • sloc: ansic: 52,384; makefile: 241; sh: 53
file content (221 lines) | stat: -rw-r--r-- 5,472 bytes parent folder | download | duplicates (4)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
\defmodule {num}

This module offers some useful constants and basic tools to 
manipulate numbers represented in different forms.

\bigskip\hrule
\code\hide
/* num.h for ANSI C */

#ifndef NUM_H
#define NUM_H
\endhide
#include <testu01/gdef.h>
\endcode

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Constants}
\code

#define num_Pi     3.14159265358979323846
\endcode
  \tab The number $\pi$.
  \endtab
\code

#define num_ebase  2.7182818284590452354
\endcode
  \tab The number $e$.
  \endtab
\code

#define num_Rac2   1.41421356237309504880
\endcode
  \tab $\sqrt{2}$, the square root of 2.
  \endtab
\code

#define num_1Rac2  0.70710678118654752440
\endcode
  \tab $1/\sqrt{2}$.
  \endtab
\code

#define num_Ln2    0.69314718055994530941
\endcode
  \tab $\ln(2)$, the natural logarithm of 2.
  \endtab
\code

#define num_1Ln2   1.44269504088896340737
\endcode
  \tab $1 / \ln(2)$.
  \endtab
\code

#define num_MaxIntDouble   9007199254740992.0
\endcode
  \tab Largest integer $n_0 = 2^{53}$ such that all integers
  $n \le n_0$ are represented  exactly as a {\tt double}.
  \endtab


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Precomputed powers}
\code

#define num_MaxTwoExp   64
\endcode
  \tab Powers of 2 up to {\tt num\_MaxTwoExp} are stored exactly 
  in the array {\tt num\_TwoExp}.
  \endtab
\code

extern double num_TwoExp[];   
\endcode
  \tab  Contains precomputed powers of 2.
  One has {\tt num\_TwoExp[i]} $= 2^i$ for $0 \le i \le$ 
  {\tt num\_MaxTwoExp}.
\endtab
\code

#define num_MAXTENNEGPOW   16
\endcode
  \tab Negative powers of 10 up to {\tt num\_MAXTENNEGPOW} are stored
  in the array {\tt num\_TENNEGPOW}.
  \endtab
\code

extern double num_TENNEGPOW[];
\endcode
 \tab Contains the precomputed negative powers of 10.
   One has {\tt TENNEGPOW[j]}$ = 10^{-j}$, for $j=0,\ldots,$
 {\tt num\_MAXTENNEGPOW}.
\endtab


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Prototypes}
\code

#define num_Log2(x) (num_1Ln2 * log(x)) 
\endcode
  \tab Gives the logarithm of $x$ in base 2.
  \endtab
\code


long num_RoundL (double x);
\endcode
  \tab Rounds $x$ to the nearest ({\tt long}) integer and returns it.
  \endtab
\code


double num_RoundD (double x);
\endcode
  \tab Rounds $x$ to the nearest ({\tt double}) integer and returns it.
  \endtab
\code


int num_IsNumber (char S[]);
\endcode 
\tab  Returns {\tt 1} if the string {\tt S} begins with a number     
   (with the possibility of spaces and a $+/-$ sign    
   before the number). For example, `` + 2'' and ``4hello''
   return {\tt 1}, while ``$-+2$'' and ``hello'' return
   {\tt 0}.
\endtab
\code


void num_IntToStrBase (long k, long b, char S[]);
\endcode
  \tab Returns in {\tt S} the string representation of {\tt k} in base
  {\tt b}.
  \endtab
\code


void num_Uint2Uchar (unsigned char output[], unsigned int input[], int L);
\endcode
  \tab Transforms the $L$ 32-bit integers contained in {\tt input} into
   $4L$ characters and puts them into {\tt output}. The order is such that 
  the 8 most significant bits of {\tt input[0]} will be in {\tt output[0]},
  the 8 least significant bits of {\tt input[0]} will be in {\tt output[3]},
  and the 8 least significant bits of {\tt input[L-1]} will be in
   {\tt output[4L-1]}. Array {\tt output} must have at least $4L$ elements.
  \endtab
\code


void num_WriteD (double x, int i, int j, int k);
\endcode
  \tab  Writes {\tt x} to current output.  Uses a total of at least {\tt i}
   positions (including the sign and point when they appear),
   {\tt j} digits after the decimal point and at least {\tt k}
   significant digits.   The number is rounded if necessary.
   If there is not enough space to print the number in decimal notation
   with at least {\tt k} significant digits
   ({\tt j} or {\tt i} is too small), it will be printed in scientific
   notation with at least {\tt k} significant digits.
   In that case, {\tt i} is increased if necessary. 
   Restriction: {\tt j} and {\tt k} must be strictly smaller than {\tt i}.
 \endtab
\code


void num_WriteBits (unsigned long x, int k);
\endcode
 \tab Writes {\tt x} in base 2 in a field of at least
  $\max\{b, |k|\}$ positions, where $b$ is the number of bits in an
  {\tt unsigned long}.
  If $k>0$, the number will be right-justified, otherwise left-justified.
 \endtab
\code


long num_MultModL (long a, long s, long c, long m);
\endcode
\tab  Returns $(as + c) \mod m$.  Uses the decomposition technique
  of \cite{rLEC91a} to avoid overflow. Supposes that $s < m$.
\endtab
\code


double num_MultModD (double a, double s, double c, double m);
\endcode
 \tab  Returns $(as+c) \mod m$, assuming that
  $a$, $s$, $c$, and $m$ are all {\em integers\/} less than $2^{35}$ 
  (represented exactly).
  Works under the assumption that all positive integers less than 
  $2^{53}$ are represented exactly in floating-point (in {\tt double}).
\endtab
\code


long num_InvEuclid (long m, long z);
\endcode
 \tab  This function computes the inverse $z^{-1}\bmod m$ by the 
  modified Euclid algorithm (see \cite[p. 325]{iKNU81a}) and returns
  the result. If the inverse does not exist, returns 0.
\endtab
\code


unsigned long num_InvExpon (int E, unsigned long z);
\endcode
 \tab
  This function computes the inverse  $z^{-1} \bmod 2^E$
  by exponentiation  and returns the result. If the inverse does not
  exist, returns 0.
  Restriction: $E$ not larger than the number of bits
  in an {\tt unsigned long}.
 \endtab

\code
\hide
#endif
\endhide
\endcode