1Stdlib.Float(3) OCaml library Stdlib.Float(3)
2
3
4
6 Stdlib.Float - no description
7
9 Module Stdlib.Float
10
12 Module Float
13 : (module Stdlib__float)
14
15
16
17
18
19
20
21
22 val zero : float
23
24 The floating point 0.
25
26
27 Since 4.08.0
28
29
30
31 val one : float
32
33 The floating-point 1.
34
35
36 Since 4.08.0
37
38
39
40 val minus_one : float
41
42 The floating-point -1.
43
44
45 Since 4.08.0
46
47
48
49 val neg : float -> float
50
51 Unary negation.
52
53
54
55 val add : float -> float -> float
56
57 Floating-point addition.
58
59
60
61 val sub : float -> float -> float
62
63 Floating-point subtraction.
64
65
66
67 val mul : float -> float -> float
68
69 Floating-point multiplication.
70
71
72
73 val div : float -> float -> float
74
75 Floating-point division.
76
77
78
79 val fma : float -> float -> float -> float
80
81
82 fma x y z returns x * y + z , with a best effort for computing this ex‐
83 pression with a single rounding, using either hardware instructions
84 (providing full IEEE compliance) or a software emulation. Note: since
85 software emulation of the fma is costly, make sure that you are using
86 hardware fma support if performance matters.
87
88
89 Since 4.08.0
90
91
92
93 val rem : float -> float -> float
94
95
96 rem a b returns the remainder of a with respect to b . The returned
97 value is a -. n *. b , where n is the quotient a /. b rounded towards
98 zero to an integer.
99
100
101
102 val succ : float -> float
103
104
105 succ x returns the floating point number right after x i.e., the small‐
106 est floating-point number greater than x . See also Float.next_after .
107
108
109 Since 4.08.0
110
111
112
113 val pred : float -> float
114
115
116 pred x returns the floating-point number right before x i.e., the
117 greatest floating-point number smaller than x . See also
118 Float.next_after .
119
120
121 Since 4.08.0
122
123
124
125 val abs : float -> float
126
127
128 abs f returns the absolute value of f .
129
130
131
132 val infinity : float
133
134 Positive infinity.
135
136
137
138 val neg_infinity : float
139
140 Negative infinity.
141
142
143
144 val nan : float
145
146 A special floating-point value denoting the result of an undefined op‐
147 eration such as 0.0 /. 0.0 . Stands for 'not a number'. Any float‐
148 ing-point operation with nan as argument returns nan as result. As for
149 floating-point comparisons, = , < , <= , > and >= return false and <>
150 returns true if one or both of their arguments is nan .
151
152
153
154 val pi : float
155
156 The constant pi.
157
158
159
160 val max_float : float
161
162 The largest positive finite value of type float .
163
164
165
166 val min_float : float
167
168 The smallest positive, non-zero, non-denormalized value of type float .
169
170
171
172 val epsilon : float
173
174 The difference between 1.0 and the smallest exactly representable
175 floating-point number greater than 1.0 .
176
177
178
179 val is_finite : float -> bool
180
181
182 is_finite x is true iff x is finite i.e., not infinite and not
183 Float.nan .
184
185
186 Since 4.08.0
187
188
189
190 val is_infinite : float -> bool
191
192
193 is_infinite x is true iff x is Float.infinity or Float.neg_infinity .
194
195
196 Since 4.08.0
197
198
199
200 val is_nan : float -> bool
201
202
203 is_nan x is true iff x is not a number (see Float.nan ).
204
205
206 Since 4.08.0
207
208
209
210 val is_integer : float -> bool
211
212
213 is_integer x is true iff x is an integer.
214
215
216 Since 4.08.0
217
218
219
220 val of_int : int -> float
221
222 Convert an integer to floating-point.
223
224
225
226 val to_int : float -> int
227
228 Truncate the given floating-point number to an integer. The result is
229 unspecified if the argument is nan or falls outside the range of repre‐
230 sentable integers.
231
232
233
234 val of_string : string -> float
235
236 Convert the given string to a float. The string is read in decimal (by
237 default) or in hexadecimal (marked by 0x or 0X ). The format of deci‐
238 mal floating-point numbers is [-] dd.ddd (e|E) [+|-] dd , where d
239 stands for a decimal digit. The format of hexadecimal floating-point
240 numbers is [-] 0(x|X) hh.hhh (p|P) [+|-] dd , where h stands for an
241 hexadecimal digit and d for a decimal digit. In both cases, at least
242 one of the integer and fractional parts must be given; the exponent
243 part is optional. The _ (underscore) character can appear anywhere in
244 the string and is ignored. Depending on the execution platforms, other
245 representations of floating-point numbers can be accepted, but should
246 not be relied upon.
247
248
249 Raises Failure if the given string is not a valid representation of a
250 float.
251
252
253
254 val of_string_opt : string -> float option
255
256 Same as of_string , but returns None instead of raising.
257
258
259
260 val to_string : float -> string
261
262 Return the string representation of a floating-point number.
263
264
265 type fpclass = fpclass =
266 | FP_normal (* Normal number, none of the below
267 *)
268 | FP_subnormal (* Number very close to 0.0, has reduced precision
269 *)
270 | FP_zero (* Number is 0.0 or -0.0
271 *)
272 | FP_infinite (* Number is positive or negative infinity
273 *)
274 | FP_nan (* Not a number: result of an undefined operation
275 *)
276
277
278 The five classes of floating-point numbers, as determined by the
279 Float.classify_float function.
280
281
282
283 val classify_float : float -> fpclass
284
285 Return the class of the given floating-point number: normal, subnormal,
286 zero, infinite, or not a number.
287
288
289
290 val pow : float -> float -> float
291
292 Exponentiation.
293
294
295
296 val sqrt : float -> float
297
298 Square root.
299
300
301
302 val exp : float -> float
303
304 Exponential.
305
306
307
308 val log : float -> float
309
310 Natural logarithm.
311
312
313
314 val log10 : float -> float
315
316 Base 10 logarithm.
317
318
319
320 val expm1 : float -> float
321
322
323 expm1 x computes exp x -. 1.0 , giving numerically-accurate results
324 even if x is close to 0.0 .
325
326
327
328 val log1p : float -> float
329
330
331 log1p x computes log(1.0 +. x) (natural logarithm), giving numeri‐
332 cally-accurate results even if x is close to 0.0 .
333
334
335
336 val cos : float -> float
337
338 Cosine. Argument is in radians.
339
340
341
342 val sin : float -> float
343
344 Sine. Argument is in radians.
345
346
347
348 val tan : float -> float
349
350 Tangent. Argument is in radians.
351
352
353
354 val acos : float -> float
355
356 Arc cosine. The argument must fall within the range [-1.0, 1.0] . Re‐
357 sult is in radians and is between 0.0 and pi .
358
359
360
361 val asin : float -> float
362
363 Arc sine. The argument must fall within the range [-1.0, 1.0] . Re‐
364 sult is in radians and is between -pi/2 and pi/2 .
365
366
367
368 val atan : float -> float
369
370 Arc tangent. Result is in radians and is between -pi/2 and pi/2 .
371
372
373
374 val atan2 : float -> float -> float
375
376
377 atan2 y x returns the arc tangent of y /. x . The signs of x and y are
378 used to determine the quadrant of the result. Result is in radians and
379 is between -pi and pi .
380
381
382
383 val hypot : float -> float -> float
384
385
386 hypot x y returns sqrt(x *. x + y *. y) , that is, the length of the
387 hypotenuse of a right-angled triangle with sides of length x and y ,
388 or, equivalently, the distance of the point (x,y) to origin. If one of
389 x or y is infinite, returns infinity even if the other is nan .
390
391
392
393 val cosh : float -> float
394
395 Hyperbolic cosine. Argument is in radians.
396
397
398
399 val sinh : float -> float
400
401 Hyperbolic sine. Argument is in radians.
402
403
404
405 val tanh : float -> float
406
407 Hyperbolic tangent. Argument is in radians.
408
409
410
411 val trunc : float -> float
412
413
414 trunc x rounds x to the nearest integer whose absolute value is less
415 than or equal to x .
416
417
418 Since 4.08.0
419
420
421
422 val round : float -> float
423
424
425 round x rounds x to the nearest integer with ties (fractional values of
426 0.5) rounded away from zero, regardless of the current rounding direc‐
427 tion. If x is an integer, +0. , -0. , nan , or infinite, x itself is
428 returned.
429
430
431 Since 4.08.0
432
433
434
435 val ceil : float -> float
436
437 Round above to an integer value. ceil f returns the least integer
438 value greater than or equal to f . The result is returned as a float.
439
440
441
442 val floor : float -> float
443
444 Round below to an integer value. floor f returns the greatest integer
445 value less than or equal to f . The result is returned as a float.
446
447
448
449 val next_after : float -> float -> float
450
451
452 next_after x y returns the next representable floating-point value fol‐
453 lowing x in the direction of y . More precisely, if y is greater
454 (resp. less) than x , it returns the smallest (resp. largest) repre‐
455 sentable number greater (resp. less) than x . If x equals y , the
456 function returns y . If x or y is nan , a nan is returned. Note that
457 next_after max_float infinity = infinity and that next_after 0. infin‐
458 ity is the smallest denormalized positive number. If x is the smallest
459 denormalized positive number, next_after x 0. = 0.
460
461
462
463 Since 4.08.0
464
465
466
467 val copy_sign : float -> float -> float
468
469
470 copy_sign x y returns a float whose absolute value is that of x and
471 whose sign is that of y . If x is nan , returns nan . If y is nan ,
472 returns either x or -. x , but it is not specified which.
473
474
475
476 val sign_bit : float -> bool
477
478
479 sign_bit x is true iff the sign bit of x is set. For example sign_bit
480 1. and signbit 0. are false while sign_bit (-1.) and sign_bit (-0.)
481 are true .
482
483
484 Since 4.08.0
485
486
487
488 val frexp : float -> float * int
489
490
491 frexp f returns the pair of the significant and the exponent of f .
492 When f is zero, the significant x and the exponent n of f are equal to
493 zero. When f is non-zero, they are defined by f = x *. 2 ** n and 0.5
494 <= x < 1.0 .
495
496
497
498 val ldexp : float -> int -> float
499
500
501 ldexp x n returns x *. 2 ** n .
502
503
504
505 val modf : float -> float * float
506
507
508 modf f returns the pair of the fractional and integral part of f .
509
510
511 type t = float
512
513
514 An alias for the type of floating-point numbers.
515
516
517
518 val compare : t -> t -> int
519
520
521 compare x y returns 0 if x is equal to y , a negative integer if x is
522 less than y , and a positive integer if x is greater than y . compare
523 treats nan as equal to itself and less than any other float value.
524 This treatment of nan ensures that compare defines a total ordering re‐
525 lation.
526
527
528
529 val equal : t -> t -> bool
530
531 The equal function for floating-point numbers, compared using
532 Float.compare .
533
534
535
536 val min : t -> t -> t
537
538
539 min x y returns the minimum of x and y . It returns nan when x or y is
540 nan . Moreover min (-0.) (+0.) = -0.
541
542
543
544 Since 4.08.0
545
546
547
548 val max : float -> float -> float
549
550
551 max x y returns the maximum of x and y . It returns nan when x or y is
552 nan . Moreover max (-0.) (+0.) = +0.
553
554
555
556 Since 4.08.0
557
558
559
560 val min_max : float -> float -> float * float
561
562
563 min_max x y is (min x y, max x y) , just more efficient.
564
565
566 Since 4.08.0
567
568
569
570 val min_num : t -> t -> t
571
572
573 min_num x y returns the minimum of x and y treating nan as missing val‐
574 ues. If both x and y are nan , nan is returned. Moreover min_num
575 (-0.) (+0.) = -0.
576
577
578
579 Since 4.08.0
580
581
582
583 val max_num : t -> t -> t
584
585
586 max_num x y returns the maximum of x and y treating nan as missing val‐
587 ues. If both x and y are nan nan is returned. Moreover max_num (-0.)
588 (+0.) = +0.
589
590
591
592 Since 4.08.0
593
594
595
596 val min_max_num : float -> float -> float * float
597
598
599 min_max_num x y is (min_num x y, max_num x y) , just more efficient.
600 Note that in particular min_max_num x nan = (x, x) and min_max_num nan
601 y = (y, y) .
602
603
604 Since 4.08.0
605
606
607
608 val hash : t -> int
609
610 The hash function for floating-point numbers.
611
612
613 module Array : sig end
614
615
616
617
618 module ArrayLabels : sig end
619
620
621
622
623
624
625
626OCamldoc 2021-01-26 Stdlib.Float(3)