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 a string representation of a floating-point number.
267
268       This  conversion  can  involve a loss of precision. For greater control
269       over the manner in which the number is printed, see Printf .
270
271       This function is an alias for string_of_float .
272
273
274       type fpclass = fpclass =
275        | FP_normal  (* Normal number, none of the below
276        *)
277        | FP_subnormal  (* Number very close to 0.0, has reduced precision
278        *)
279        | FP_zero  (* Number is 0.0 or -0.0
280        *)
281        | FP_infinite  (* Number is positive or negative infinity
282        *)
283        | FP_nan  (* Not a number: result of an undefined operation
284        *)
285
286
287       The five classes  of  floating-point  numbers,  as  determined  by  the
288       Float.classify_float function.
289
290
291
292       val classify_float : float -> fpclass
293
294       Return the class of the given floating-point number: normal, subnormal,
295       zero, infinite, or not a number.
296
297
298
299       val pow : float -> float -> float
300
301       Exponentiation.
302
303
304
305       val sqrt : float -> float
306
307       Square root.
308
309
310
311       val cbrt : float -> float
312
313       Cube root.
314
315
316       Since 4.13.0
317
318
319
320       val exp : float -> float
321
322       Exponential.
323
324
325
326       val exp2 : float -> float
327
328       Base 2 exponential function.
329
330
331       Since 4.13.0
332
333
334
335       val log : float -> float
336
337       Natural logarithm.
338
339
340
341       val log10 : float -> float
342
343       Base 10 logarithm.
344
345
346
347       val log2 : float -> float
348
349       Base 2 logarithm.
350
351
352       Since 4.13.0
353
354
355
356       val expm1 : float -> float
357
358
359       expm1 x computes exp x -. 1.0  ,  giving  numerically-accurate  results
360       even if x is close to 0.0 .
361
362
363
364       val log1p : float -> float
365
366
367       log1p  x  computes  log(1.0  +.  x) (natural logarithm), giving numeri‐
368       cally-accurate results even if x is close to 0.0 .
369
370
371
372       val cos : float -> float
373
374       Cosine.  Argument is in radians.
375
376
377
378       val sin : float -> float
379
380       Sine.  Argument is in radians.
381
382
383
384       val tan : float -> float
385
386       Tangent.  Argument is in radians.
387
388
389
390       val acos : float -> float
391
392       Arc cosine.  The argument must fall within the range [-1.0, 1.0] .  Re‐
393       sult is in radians and is between 0.0 and pi .
394
395
396
397       val asin : float -> float
398
399       Arc  sine.   The argument must fall within the range [-1.0, 1.0] .  Re‐
400       sult is in radians and is between -pi/2 and pi/2 .
401
402
403
404       val atan : float -> float
405
406       Arc tangent.  Result is in radians and is between -pi/2 and pi/2 .
407
408
409
410       val atan2 : float -> float -> float
411
412
413       atan2 y x returns the arc tangent of y /. x .  The signs of x and y are
414       used to determine the quadrant of the result.  Result is in radians and
415       is between -pi and pi .
416
417
418
419       val hypot : float -> float -> float
420
421
422       hypot x y returns sqrt(x *. x + y *. y) , that is, the  length  of  the
423       hypotenuse  of  a  right-angled triangle with sides of length x and y ,
424       or, equivalently, the distance of the point (x,y) to origin.  If one of
425       x or y is infinite, returns infinity even if the other is nan .
426
427
428
429       val cosh : float -> float
430
431       Hyperbolic cosine.  Argument is in radians.
432
433
434
435       val sinh : float -> float
436
437       Hyperbolic sine.  Argument is in radians.
438
439
440
441       val tanh : float -> float
442
443       Hyperbolic tangent.  Argument is in radians.
444
445
446
447       val acosh : float -> float
448
449       Hyperbolic  arc  cosine.  The argument must fall within the range [1.0,
450       inf] .  Result is in radians and is between 0.0 and inf .
451
452
453       Since 4.13.0
454
455
456
457       val asinh : float -> float
458
459       Hyperbolic arc sine.  The argument and result  range  over  the  entire
460       real line.  Result is in radians.
461
462
463       Since 4.13.0
464
465
466
467       val atanh : float -> float
468
469       Hyperbolic arc tangent.  The argument must fall within the range [-1.0,
470       1.0] .  Result is in radians and ranges over the entire real line.
471
472
473       Since 4.13.0
474
475
476
477       val erf : float -> float
478
479       Error function.  The argument ranges over the entire  real  line.   The
480       result is always within [-1.0, 1.0] .
481
482
483       Since 4.13.0
484
485
486
487       val erfc : float -> float
488
489       Complementary  error  function  (  erfc  x = 1 - erf x ).  The argument
490       ranges over the entire real line.  The result is always  within  [-1.0,
491       1.0] .
492
493
494       Since 4.13.0
495
496
497
498       val trunc : float -> float
499
500
501       trunc  x  rounds  x to the nearest integer whose absolute value is less
502       than or equal to x .
503
504
505       Since 4.08.0
506
507
508
509       val round : float -> float
510
511
512       round x rounds x to the nearest integer with ties (fractional values of
513       0.5)  rounded away from zero, regardless of the current rounding direc‐
514       tion.  If x is an integer, +0.  , -0.  , nan , or infinite, x itself is
515       returned.
516
517       On  64-bit  mingw-w64,  this function may be emulated owing to a bug in
518       the C runtime library (CRT) on this platform.
519
520
521       Since 4.08.0
522
523
524
525       val ceil : float -> float
526
527       Round above to an integer value.  ceil  f  returns  the  least  integer
528       value greater than or equal to f .  The result is returned as a float.
529
530
531
532       val floor : float -> float
533
534       Round  below to an integer value.  floor f returns the greatest integer
535       value less than or equal to f .  The result is returned as a float.
536
537
538
539       val next_after : float -> float -> float
540
541
542       next_after x y returns the next representable floating-point value fol‐
543       lowing  x  in  the  direction  of  y .  More precisely, if y is greater
544       (resp. less) than x , it returns the smallest  (resp.  largest)  repre‐
545       sentable  number  greater  (resp.  less)  than x .  If x equals y , the
546       function returns y .  If x or y is nan , a nan is returned.  Note  that
547       next_after  max_float infinity = infinity and that next_after 0. infin‐
548       ity is the smallest denormalized positive number.  If x is the smallest
549       denormalized positive number, next_after x 0. = 0.
550
551
552
553       Since 4.08.0
554
555
556
557       val copy_sign : float -> float -> float
558
559
560       copy_sign  x  y  returns  a float whose absolute value is that of x and
561       whose sign is that of y .  If x is nan , returns nan .  If y is  nan  ,
562       returns either x or -. x , but it is not specified which.
563
564
565
566       val sign_bit : float -> bool
567
568
569       sign_bit  x is true if and only if the sign bit of x is set.  For exam‐
570       ple sign_bit 1.  and signbit 0.  are false while  sign_bit  (-1.)   and
571       sign_bit (-0.)  are true .
572
573
574       Since 4.08.0
575
576
577
578       val frexp : float -> float * int
579
580
581       frexp  f  returns  the  pair of the significant and the exponent of f .
582       When f is zero, the significant x and the exponent n of f are equal  to
583       zero.   When f is non-zero, they are defined by f = x *. 2 ** n and 0.5
584       <= x < 1.0 .
585
586
587
588       val ldexp : float -> int -> float
589
590
591       ldexp x n returns x *. 2 ** n .
592
593
594
595       val modf : float -> float * float
596
597
598       modf f returns the pair of the fractional and integral part of f .
599
600
601       type t = float
602
603
604       An alias for the type of floating-point numbers.
605
606
607
608       val compare : t -> t -> int
609
610
611       compare x y returns 0 if x is equal to y , a negative integer if  x  is
612       less  than y , and a positive integer if x is greater than y .  compare
613       treats nan as equal to itself and less  than  any  other  float  value.
614       This treatment of nan ensures that compare defines a total ordering re‐
615       lation.
616
617
618
619       val equal : t -> t -> bool
620
621       The  equal  function  for  floating-point   numbers,   compared   using
622       Float.compare .
623
624
625
626       val min : t -> t -> t
627
628
629       min x y returns the minimum of x and y .  It returns nan when x or y is
630       nan .  Moreover min (-0.) (+0.) = -0.
631
632
633
634       Since 4.08.0
635
636
637
638       val max : float -> float -> float
639
640
641       max x y returns the maximum of x and y .  It returns nan when x or y is
642       nan .  Moreover max (-0.) (+0.) = +0.
643
644
645
646       Since 4.08.0
647
648
649
650       val min_max : float -> float -> float * float
651
652
653       min_max x y is (min x y, max x y) , just more efficient.
654
655
656       Since 4.08.0
657
658
659
660       val min_num : t -> t -> t
661
662
663       min_num x y returns the minimum of x and y treating nan as missing val‐
664       ues.  If both x and y are nan ,  nan  is  returned.   Moreover  min_num
665       (-0.) (+0.) = -0.
666
667
668
669       Since 4.08.0
670
671
672
673       val max_num : t -> t -> t
674
675
676       max_num x y returns the maximum of x and y treating nan as missing val‐
677       ues.  If both x and y are nan nan is returned.  Moreover max_num  (-0.)
678       (+0.) = +0.
679
680
681
682       Since 4.08.0
683
684
685
686       val min_max_num : float -> float -> float * float
687
688
689       min_max_num  x  y  is (min_num x y, max_num x y) , just more efficient.
690       Note that in particular min_max_num x nan = (x, x) and min_max_num  nan
691       y = (y, y) .
692
693
694       Since 4.08.0
695
696
697
698       val hash : t -> int
699
700       The hash function for floating-point numbers.
701
702
703       module Array : sig end
704
705
706       Float arrays with packed representation.
707
708
709       module ArrayLabels : sig end
710
711
712       Float arrays with packed representation (labeled functions).
713
714
715
716
717
718OCamldoc                          2023-01-23                   Stdlib.Float(3)
Impressum