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

NAME

6       Stdlib.Float - no description
7

Module

9       Module   Stdlib.Float
10

Documentation

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.
85
86       On  64-bit  Cygwin,  64-bit  mingw-w64  and MSVC 2017 and earlier, this
87       function may be emulated owing to known bugs on  limitations  on  these
88       platforms.   Note:  since software emulation of the fma is costly, make
89       sure that you are using hardware fma support if performance matters.
90
91
92       Since 4.08.0
93
94
95
96       val rem : float -> float -> float
97
98
99       rem a b returns the remainder of a with respect to b  .   The  returned
100       value  is  a -. n *. b , where n is the quotient a /. b rounded towards
101       zero to an integer.
102
103
104
105       val succ : float -> float
106
107
108       succ x returns the floating point number right after x i.e., the small‐
109       est floating-point number greater than x .  See also Float.next_after .
110
111
112       Since 4.08.0
113
114
115
116       val pred : float -> float
117
118
119       pred  x  returns  the  floating-point  number  right before x i.e., the
120       greatest  floating-point  number   smaller   than   x   .    See   also
121       Float.next_after .
122
123
124       Since 4.08.0
125
126
127
128       val abs : float -> float
129
130
131       abs f returns the absolute value of f .
132
133
134
135       val infinity : float
136
137       Positive infinity.
138
139
140
141       val neg_infinity : float
142
143       Negative infinity.
144
145
146
147       val nan : float
148
149       A  special floating-point value denoting the result of an undefined op‐
150       eration such as 0.0 /. 0.0 .  Stands for 'not a  number'.   Any  float‐
151       ing-point operation with nan as argument returns nan as result.  As for
152       floating-point comparisons, = , < , <= , > and >= return false  and  <>
153       returns true if one or both of their arguments is nan .
154
155
156
157       val pi : float
158
159       The constant pi.
160
161
162
163       val max_float : float
164
165       The largest positive finite value of type float .
166
167
168
169       val min_float : float
170
171       The smallest positive, non-zero, non-denormalized value of type float .
172
173
174
175       val epsilon : float
176
177       The  difference  between  1.0  and  the  smallest exactly representable
178       floating-point number greater than 1.0 .
179
180
181
182       val is_finite : float -> bool
183
184
185       is_finite x is true if and only if x is finite i.e., not  infinite  and
186       not Float.nan .
187
188
189       Since 4.08.0
190
191
192
193       val is_infinite : float -> bool
194
195
196       is_infinite   x  is  true  if  and  only  if  x  is  Float.infinity  or
197       Float.neg_infinity .
198
199
200       Since 4.08.0
201
202
203
204       val is_nan : float -> bool
205
206
207       is_nan x is true if and only if x is not a number (see Float.nan ).
208
209
210       Since 4.08.0
211
212
213
214       val is_integer : float -> bool
215
216
217       is_integer x is true if and only if x is an integer.
218
219
220       Since 4.08.0
221
222
223
224       val of_int : int -> float
225
226       Convert an integer to floating-point.
227
228
229
230       val to_int : float -> int
231
232       Truncate the given floating-point number to an integer.  The result  is
233       unspecified if the argument is nan or falls outside the range of repre‐
234       sentable integers.
235
236
237
238       val of_string : string -> float
239
240       Convert the given string to a float.  The string is read in decimal (by
241       default)  or in hexadecimal (marked by 0x or 0X ).  The format of deci‐
242       mal floating-point numbers is [-] dd.ddd  (e|E)  [+|-]  dd  ,  where  d
243       stands  for  a decimal digit.  The format of hexadecimal floating-point
244       numbers is [-] 0(x|X) hh.hhh (p|P) [+|-] dd , where  h  stands  for  an
245       hexadecimal  digit  and d for a decimal digit.  In both cases, at least
246       one of the integer and fractional parts must  be  given;  the  exponent
247       part  is optional.  The _ (underscore) character can appear anywhere in
248       the string and is ignored.  Depending on the execution platforms, other
249       representations  of  floating-point numbers can be accepted, but should
250       not be relied upon.
251
252
253       Raises Failure if the given string is not a valid representation  of  a
254       float.
255
256
257
258       val of_string_opt : string -> float option
259
260       Same as of_string , but returns None instead of raising.
261
262
263
264       val to_string : float -> string
265
266       Return the string representation of a floating-point number.
267
268
269       type fpclass = fpclass =
270        | FP_normal  (* Normal number, none of the below
271        *)
272        | FP_subnormal  (* Number very close to 0.0, has reduced precision
273        *)
274        | FP_zero  (* Number is 0.0 or -0.0
275        *)
276        | FP_infinite  (* Number is positive or negative infinity
277        *)
278        | FP_nan  (* Not a number: result of an undefined operation
279        *)
280
281
282       The  five  classes  of  floating-point  numbers,  as  determined by the
283       Float.classify_float function.
284
285
286
287       val classify_float : float -> fpclass
288
289       Return the class of the given floating-point number: normal, subnormal,
290       zero, infinite, or not a number.
291
292
293
294       val pow : float -> float -> float
295
296       Exponentiation.
297
298
299
300       val sqrt : float -> float
301
302       Square root.
303
304
305
306       val cbrt : float -> float
307
308       Cube root.
309
310
311       Since 4.13.0
312
313
314
315       val exp : float -> float
316
317       Exponential.
318
319
320
321       val exp2 : float -> float
322
323       Base 2 exponential function.
324
325
326       Since 4.13.0
327
328
329
330       val log : float -> float
331
332       Natural logarithm.
333
334
335
336       val log10 : float -> float
337
338       Base 10 logarithm.
339
340
341
342       val log2 : float -> float
343
344       Base 2 logarithm.
345
346
347       Since 4.13.0
348
349
350
351       val expm1 : float -> float
352
353
354       expm1  x  computes  exp  x -. 1.0 , giving numerically-accurate results
355       even if x is close to 0.0 .
356
357
358
359       val log1p : float -> float
360
361
362       log1p x computes log(1.0 +.  x)  (natural  logarithm),  giving  numeri‐
363       cally-accurate results even if x is close to 0.0 .
364
365
366
367       val cos : float -> float
368
369       Cosine.  Argument is in radians.
370
371
372
373       val sin : float -> float
374
375       Sine.  Argument is in radians.
376
377
378
379       val tan : float -> float
380
381       Tangent.  Argument is in radians.
382
383
384
385       val acos : float -> float
386
387       Arc cosine.  The argument must fall within the range [-1.0, 1.0] .  Re‐
388       sult is in radians and is between 0.0 and pi .
389
390
391
392       val asin : float -> float
393
394       Arc sine.  The argument must fall within the range [-1.0, 1.0]  .   Re‐
395       sult is in radians and is between -pi/2 and pi/2 .
396
397
398
399       val atan : float -> float
400
401       Arc tangent.  Result is in radians and is between -pi/2 and pi/2 .
402
403
404
405       val atan2 : float -> float -> float
406
407
408       atan2 y x returns the arc tangent of y /. x .  The signs of x and y are
409       used to determine the quadrant of the result.  Result is in radians and
410       is between -pi and pi .
411
412
413
414       val hypot : float -> float -> float
415
416
417       hypot  x  y  returns sqrt(x *. x + y *. y) , that is, the length of the
418       hypotenuse of a right-angled triangle with sides of length x  and  y  ,
419       or, equivalently, the distance of the point (x,y) to origin.  If one of
420       x or y is infinite, returns infinity even if the other is nan .
421
422
423
424       val cosh : float -> float
425
426       Hyperbolic cosine.  Argument is in radians.
427
428
429
430       val sinh : float -> float
431
432       Hyperbolic sine.  Argument is in radians.
433
434
435
436       val tanh : float -> float
437
438       Hyperbolic tangent.  Argument is in radians.
439
440
441
442       val acosh : float -> float
443
444       Hyperbolic arc cosine.  The argument must fall within the  range  [1.0,
445       inf] .  Result is in radians and is between 0.0 and inf .
446
447
448       Since 4.13.0
449
450
451
452       val asinh : float -> float
453
454       Hyperbolic  arc  sine.   The  argument and result range over the entire
455       real line.  Result is in radians.
456
457
458       Since 4.13.0
459
460
461
462       val atanh : float -> float
463
464       Hyperbolic arc tangent.  The argument must fall within the range [-1.0,
465       1.0] .  Result is in radians and ranges over the entire real line.
466
467
468       Since 4.13.0
469
470
471
472       val erf : float -> float
473
474       Error  function.   The  argument ranges over the entire real line.  The
475       result is always within [-1.0, 1.0] .
476
477
478       Since 4.13.0
479
480
481
482       val erfc : float -> float
483
484       Complementary error function ( erfc x = 1 -  erf  x  ).   The  argument
485       ranges  over  the entire real line.  The result is always within [-1.0,
486       1.0] .
487
488
489       Since 4.13.0
490
491
492
493       val trunc : float -> float
494
495
496       trunc x rounds x to the nearest integer whose absolute  value  is  less
497       than or equal to x .
498
499
500       Since 4.08.0
501
502
503
504       val round : float -> float
505
506
507       round x rounds x to the nearest integer with ties (fractional values of
508       0.5) rounded away from zero, regardless of the current rounding  direc‐
509       tion.  If x is an integer, +0.  , -0.  , nan , or infinite, x itself is
510       returned.
511
512       On 64-bit mingw-w64, this function may be emulated owing to  a  bug  in
513       the C runtime library (CRT) on this platform.
514
515
516       Since 4.08.0
517
518
519
520       val ceil : float -> float
521
522       Round  above  to  an  integer  value.  ceil f returns the least integer
523       value greater than or equal to f .  The result is returned as a float.
524
525
526
527       val floor : float -> float
528
529       Round below to an integer value.  floor f returns the greatest  integer
530       value less than or equal to f .  The result is returned as a float.
531
532
533
534       val next_after : float -> float -> float
535
536
537       next_after x y returns the next representable floating-point value fol‐
538       lowing x in the direction of y .   More  precisely,  if  y  is  greater
539       (resp.  less)  than  x , it returns the smallest (resp. largest) repre‐
540       sentable number greater (resp. less) than x .  If  x  equals  y  ,  the
541       function  returns y .  If x or y is nan , a nan is returned.  Note that
542       next_after max_float infinity = infinity and that next_after 0.  infin‐
543       ity is the smallest denormalized positive number.  If x is the smallest
544       denormalized positive number, next_after x 0. = 0.
545
546
547
548       Since 4.08.0
549
550
551
552       val copy_sign : float -> float -> float
553
554
555       copy_sign x y returns a float whose absolute value is  that  of  x  and
556       whose  sign  is that of y .  If x is nan , returns nan .  If y is nan ,
557       returns either x or -. x , but it is not specified which.
558
559
560
561       val sign_bit : float -> bool
562
563
564       sign_bit x is true if and only if the sign bit of x is set.  For  exam‐
565       ple  sign_bit  1.   and signbit 0.  are false while sign_bit (-1.)  and
566       sign_bit (-0.)  are true .
567
568
569       Since 4.08.0
570
571
572
573       val frexp : float -> float * int
574
575
576       frexp f returns the pair of the significant and the  exponent  of  f  .
577       When  f is zero, the significant x and the exponent n of f are equal to
578       zero.  When f is non-zero, they are defined by f = x *. 2 ** n and  0.5
579       <= x < 1.0 .
580
581
582
583       val ldexp : float -> int -> float
584
585
586       ldexp x n returns x *. 2 ** n .
587
588
589
590       val modf : float -> float * float
591
592
593       modf f returns the pair of the fractional and integral part of f .
594
595
596       type t = float
597
598
599       An alias for the type of floating-point numbers.
600
601
602
603       val compare : t -> t -> int
604
605
606       compare  x  y returns 0 if x is equal to y , a negative integer if x is
607       less than y , and a positive integer if x is greater than y .   compare
608       treats  nan  as  equal  to  itself and less than any other float value.
609       This treatment of nan ensures that compare defines a total ordering re‐
610       lation.
611
612
613
614       val equal : t -> t -> bool
615
616       The   equal   function   for  floating-point  numbers,  compared  using
617       Float.compare .
618
619
620
621       val min : t -> t -> t
622
623
624       min x y returns the minimum of x and y .  It returns nan when x or y is
625       nan .  Moreover min (-0.) (+0.) = -0.
626
627
628
629       Since 4.08.0
630
631
632
633       val max : float -> float -> float
634
635
636       max x y returns the maximum of x and y .  It returns nan when x or y is
637       nan .  Moreover max (-0.) (+0.) = +0.
638
639
640
641       Since 4.08.0
642
643
644
645       val min_max : float -> float -> float * float
646
647
648       min_max x y is (min x y, max x y) , just more efficient.
649
650
651       Since 4.08.0
652
653
654
655       val min_num : t -> t -> t
656
657
658       min_num x y returns the minimum of x and y treating nan as missing val‐
659       ues.   If  both  x  and  y are nan , nan is returned.  Moreover min_num
660       (-0.) (+0.) = -0.
661
662
663
664       Since 4.08.0
665
666
667
668       val max_num : t -> t -> t
669
670
671       max_num x y returns the maximum of x and y treating nan as missing val‐
672       ues.   If both x and y are nan nan is returned.  Moreover max_num (-0.)
673       (+0.) = +0.
674
675
676
677       Since 4.08.0
678
679
680
681       val min_max_num : float -> float -> float * float
682
683
684       min_max_num x y is (min_num x y, max_num x y) ,  just  more  efficient.
685       Note  that in particular min_max_num x nan = (x, x) and min_max_num nan
686       y = (y, y) .
687
688
689       Since 4.08.0
690
691
692
693       val hash : t -> int
694
695       The hash function for floating-point numbers.
696
697
698       module Array : sig end
699
700
701       Float arrays with packed representation.
702
703
704       module ArrayLabels : sig end
705
706
707       Float arrays with packed representation (labeled functions).
708
709
710
711
712
713OCamldoc                          2022-07-22                   Stdlib.Float(3)
Impressum