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