1Float(3)                         OCaml library                        Float(3)
2
3
4

NAME

6       Float -  Floating-point arithmetic
7

Module

9       Module   Float
10

Documentation

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