1Num(3) OCamldoc Num(3)
2
3
4
6 Num - Operation on arbitrary-precision numbers.
7
9 Module Num
10
12 Module Num
13 : sig end
14
15
16 Operation on arbitrary-precision numbers.
17
18 Numbers (type num ) are arbitrary-precision rational numbers, plus the
19 special elements 1/0 (infinity) and 0/0 (undefined).
20
21
22
23
24
25 type num =
26 | Int of int
27 | Big_int of Big_int.big_int
28 | Ratio of Ratio.ratio
29
30
31 The type of numbers.
32
33
34
35
36 === Arithmetic operations ===
37
38
39 val (+/) : num -> num -> num
40
41 Same as Num.add_num .
42
43
44
45 val add_num : num -> num -> num
46
47 Addition
48
49
50
51 val minus_num : num -> num
52
53 Unary negation.
54
55
56
57 val (-/) : num -> num -> num
58
59 Same as Num.sub_num .
60
61
62
63 val sub_num : num -> num -> num
64
65 Subtraction
66
67
68
69 val ( */ ) : num -> num -> num
70
71 Same as Num.mult_num .
72
73
74
75 val mult_num : num -> num -> num
76
77 Multiplication
78
79
80
81 val square_num : num -> num
82
83 Squaring
84
85
86
87 val (//) : num -> num -> num
88
89 Same as Num.div_num .
90
91
92
93 val div_num : num -> num -> num
94
95 Division
96
97
98
99 val quo_num : num -> num -> num
100
101 Euclidean division: quotient.
102
103
104
105 val mod_num : num -> num -> num
106
107 Euclidean division: remainder.
108
109
110
111 val ( **/ ) : num -> num -> num
112
113 Same as Num.power_num .
114
115
116
117 val power_num : num -> num -> num
118
119 Exponentiation
120
121
122
123 val abs_num : num -> num
124
125 Absolute value.
126
127
128
129 val succ_num : num -> num
130
131
132 succ n is n+1
133
134
135
136
137 val pred_num : num -> num
138
139
140 pred n is n-1
141
142
143
144
145 val incr_num : num Pervasives.ref -> unit
146
147
148 incr r is r:=!r+1 , where r is a reference to a number.
149
150
151
152 val decr_num : num Pervasives.ref -> unit
153
154
155 decr r is r:=!r-1 , where r is a reference to a number.
156
157
158
159 val is_integer_num : num -> bool
160
161 Test if a number is an integer
162
163
164
165
166 === The four following functions approximate a number by an integer :
167 ===
168
169
170 val integer_num : num -> num
171
172
173 integer_num n returns the integer closest to n . In case of ties,
174 rounds towards zero.
175
176
177
178 val floor_num : num -> num
179
180
181 floor_num n returns the largest integer smaller or equal to n .
182
183
184
185 val round_num : num -> num
186
187
188 round_num n returns the integer closest to n . In case of ties, rounds
189 off zero.
190
191
192
193 val ceiling_num : num -> num
194
195
196 ceiling_num n returns the smallest integer bigger or equal to n .
197
198
199
200 val sign_num : num -> int
201
202 Return -1 , 0 or 1 according to the sign of the argument.
203
204
205
206
207 === Comparisons between numbers ===
208
209
210 val (=/) : num -> num -> bool
211
212
213
214
215 val (</) : num -> num -> bool
216
217
218
219
220 val (>/) : num -> num -> bool
221
222
223
224
225 val (<=/) : num -> num -> bool
226
227
228
229
230 val (>=/) : num -> num -> bool
231
232
233
234
235 val (<>/) : num -> num -> bool
236
237
238
239
240 val eq_num : num -> num -> bool
241
242
243
244
245 val lt_num : num -> num -> bool
246
247
248
249
250 val le_num : num -> num -> bool
251
252
253
254
255 val gt_num : num -> num -> bool
256
257
258
259
260 val ge_num : num -> num -> bool
261
262
263
264
265 val compare_num : num -> num -> int
266
267 Return -1 , 0 or 1 if the first argument is less than, equal to, or
268 greater than the second argument.
269
270
271
272 val max_num : num -> num -> num
273
274 Return the greater of the two arguments.
275
276
277
278 val min_num : num -> num -> num
279
280 Return the smaller of the two arguments.
281
282
283
284
285 === Coercions with strings ===
286
287
288 val string_of_num : num -> string
289
290 Convert a number to a string, using fractional notation.
291
292
293
294 val approx_num_fix : int -> num -> string
295
296 See Num.approx_num_exp .
297
298
299
300 val approx_num_exp : int -> num -> string
301
302 Approximate a number by a decimal. The first argument is the required
303 precision. The second argument is the number to approximate.
304 Num.approx_num_fix uses decimal notation; the first argument is the
305 number of digits after the decimal point. approx_num_exp uses scien‐
306 tific (exponential) notation; the first argument is the number of dig‐
307 its in the mantissa.
308
309
310
311 val num_of_string : string -> num
312
313 Convert a string to a number. Raise Failure num_of_string if the given
314 string is not a valid representation of an integer
315
316
317
318 val num_of_string_opt : string -> num option
319
320 Convert a string to a number. Return None if the given string is not a
321 valid representation of an integer.
322
323
324 Since 4.05
325
326
327
328
329 === Coercions between numerical types ===
330
331
332 val int_of_num : num -> int
333
334
335
336
337 val int_of_num_opt : num -> int option
338
339 Since 4.05.0
340
341
342
343 val num_of_int : int -> num
344
345
346
347
348 val nat_of_num : num -> Nat.nat
349
350
351
352
353 val nat_of_num_opt : num -> Nat.nat option
354
355 Since 4.05.0
356
357
358
359 val num_of_nat : Nat.nat -> num
360
361
362
363
364 val num_of_big_int : Big_int.big_int -> num
365
366
367
368
369 val big_int_of_num : num -> Big_int.big_int
370
371
372
373
374 val big_int_of_num_opt : num -> Big_int.big_int option
375
376 Since 4.05.0
377
378
379
380 val ratio_of_num : num -> Ratio.ratio
381
382
383
384
385 val num_of_ratio : Ratio.ratio -> num
386
387
388
389
390 val float_of_num : num -> float
391
392
393
394
395
396
3972018-04-14 source: Num(3)