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.  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 if and only if x is finite i.e., not infinite and
183       not 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  if  and  only  if  x  is  Float.infinity   or
194       Float.neg_infinity .
195
196
197       Since 4.08.0
198
199
200
201       val is_nan : float -> bool
202
203
204       is_nan x is true if and only if x is not a number (see Float.nan ).
205
206
207       Since 4.08.0
208
209
210
211       val is_integer : float -> bool
212
213
214       is_integer x is true if and only if x is an integer.
215
216
217       Since 4.08.0
218
219
220
221       val of_int : int -> float
222
223       Convert an integer to floating-point.
224
225
226
227       val to_int : float -> int
228
229       Truncate  the given floating-point number to an integer.  The result is
230       unspecified if the argument is nan or falls outside the range of repre‐
231       sentable integers.
232
233
234
235       val of_string : string -> float
236
237       Convert the given string to a float.  The string is read in decimal (by
238       default) or in hexadecimal (marked by 0x or 0X ).  The format of  deci‐
239       mal  floating-point  numbers  is  [-]  dd.ddd  (e|E) [+|-] dd , where d
240       stands for a decimal digit.  The format of  hexadecimal  floating-point
241       numbers  is  [-]  0(x|X)  hh.hhh (p|P) [+|-] dd , where h stands for an
242       hexadecimal digit and d for a decimal digit.  In both cases,  at  least
243       one  of  the  integer  and fractional parts must be given; the exponent
244       part is optional.  The _ (underscore) character can appear anywhere  in
245       the string and is ignored.  Depending on the execution platforms, other
246       representations of floating-point numbers can be accepted,  but  should
247       not be relied upon.
248
249
250       Raises  Failure  if the given string is not a valid representation of a
251       float.
252
253
254
255       val of_string_opt : string -> float option
256
257       Same as of_string , but returns None instead of raising.
258
259
260
261       val to_string : float -> string
262
263       Return the string representation of a floating-point number.
264
265
266       type fpclass = fpclass =
267        | FP_normal  (* Normal number, none of the below
268        *)
269        | FP_subnormal  (* Number very close to 0.0, has reduced precision
270        *)
271        | FP_zero  (* Number is 0.0 or -0.0
272        *)
273        | FP_infinite  (* Number is positive or negative infinity
274        *)
275        | FP_nan  (* Not a number: result of an undefined operation
276        *)
277
278
279       The five classes  of  floating-point  numbers,  as  determined  by  the
280       Float.classify_float function.
281
282
283
284       val classify_float : float -> fpclass
285
286       Return the class of the given floating-point number: normal, subnormal,
287       zero, infinite, or not a number.
288
289
290
291       val pow : float -> float -> float
292
293       Exponentiation.
294
295
296
297       val sqrt : float -> float
298
299       Square root.
300
301
302
303       val exp : float -> float
304
305       Exponential.
306
307
308
309       val log : float -> float
310
311       Natural logarithm.
312
313
314
315       val log10 : float -> float
316
317       Base 10 logarithm.
318
319
320
321       val expm1 : float -> float
322
323
324       expm1 x computes exp x -. 1.0  ,  giving  numerically-accurate  results
325       even if x is close to 0.0 .
326
327
328
329       val log1p : float -> float
330
331
332       log1p  x  computes  log(1.0  +.  x) (natural logarithm), giving numeri‐
333       cally-accurate results even if x is close to 0.0 .
334
335
336
337       val cos : float -> float
338
339       Cosine.  Argument is in radians.
340
341
342
343       val sin : float -> float
344
345       Sine.  Argument is in radians.
346
347
348
349       val tan : float -> float
350
351       Tangent.  Argument is in radians.
352
353
354
355       val acos : float -> float
356
357       Arc cosine.  The argument must fall within the range [-1.0, 1.0] .  Re‐
358       sult is in radians and is between 0.0 and pi .
359
360
361
362       val asin : float -> float
363
364       Arc  sine.   The argument must fall within the range [-1.0, 1.0] .  Re‐
365       sult is in radians and is between -pi/2 and pi/2 .
366
367
368
369       val atan : float -> float
370
371       Arc tangent.  Result is in radians and is between -pi/2 and pi/2 .
372
373
374
375       val atan2 : float -> float -> float
376
377
378       atan2 y x returns the arc tangent of y /. x .  The signs of x and y are
379       used to determine the quadrant of the result.  Result is in radians and
380       is between -pi and pi .
381
382
383
384       val hypot : float -> float -> float
385
386
387       hypot x y returns sqrt(x *. x + y *. y) , that is, the  length  of  the
388       hypotenuse  of  a  right-angled triangle with sides of length x and y ,
389       or, equivalently, the distance of the point (x,y) to origin.  If one of
390       x or y is infinite, returns infinity even if the other is nan .
391
392
393
394       val cosh : float -> float
395
396       Hyperbolic cosine.  Argument is in radians.
397
398
399
400       val sinh : float -> float
401
402       Hyperbolic sine.  Argument is in radians.
403
404
405
406       val tanh : float -> float
407
408       Hyperbolic tangent.  Argument is in radians.
409
410
411
412       val trunc : float -> float
413
414
415       trunc  x  rounds  x to the nearest integer whose absolute value is less
416       than or equal to x .
417
418
419       Since 4.08.0
420
421
422
423       val round : float -> float
424
425
426       round x rounds x to the nearest integer with ties (fractional values of
427       0.5)  rounded away from zero, regardless of the current rounding direc‐
428       tion.  If x is an integer, +0.  , -0.  , nan , or infinite, x itself is
429       returned.
430
431
432       Since 4.08.0
433
434
435
436       val ceil : float -> float
437
438       Round  above  to  an  integer  value.  ceil f returns the least integer
439       value greater than or equal to f .  The result is returned as a float.
440
441
442
443       val floor : float -> float
444
445       Round below to an integer value.  floor f returns the greatest  integer
446       value less than or equal to f .  The result is returned as a float.
447
448
449
450       val next_after : float -> float -> float
451
452
453       next_after x y returns the next representable floating-point value fol‐
454       lowing x in the direction of y .   More  precisely,  if  y  is  greater
455       (resp.  less)  than  x , it returns the smallest (resp. largest) repre‐
456       sentable number greater (resp. less) than x .  If  x  equals  y  ,  the
457       function  returns y .  If x or y is nan , a nan is returned.  Note that
458       next_after max_float infinity = infinity and that next_after 0.  infin‐
459       ity is the smallest denormalized positive number.  If x is the smallest
460       denormalized positive number, next_after x 0. = 0.
461
462
463
464       Since 4.08.0
465
466
467
468       val copy_sign : float -> float -> float
469
470
471       copy_sign x y returns a float whose absolute value is  that  of  x  and
472       whose  sign  is that of y .  If x is nan , returns nan .  If y is nan ,
473       returns either x or -. x , but it is not specified which.
474
475
476
477       val sign_bit : float -> bool
478
479
480       sign_bit x is true if and only if the sign bit of x is set.  For  exam‐
481       ple  sign_bit  1.   and signbit 0.  are false while sign_bit (-1.)  and
482       sign_bit (-0.)  are true .
483
484
485       Since 4.08.0
486
487
488
489       val frexp : float -> float * int
490
491
492       frexp f returns the pair of the significant and the  exponent  of  f  .
493       When  f is zero, the significant x and the exponent n of f are equal to
494       zero.  When f is non-zero, they are defined by f = x *. 2 ** n and  0.5
495       <= x < 1.0 .
496
497
498
499       val ldexp : float -> int -> float
500
501
502       ldexp x n returns x *. 2 ** n .
503
504
505
506       val modf : float -> float * float
507
508
509       modf f returns the pair of the fractional and integral part of f .
510
511
512       type t = float
513
514
515       An alias for the type of floating-point numbers.
516
517
518
519       val compare : t -> t -> int
520
521
522       compare  x  y returns 0 if x is equal to y , a negative integer if x is
523       less than y , and a positive integer if x is greater than y .   compare
524       treats  nan  as  equal  to  itself and less than any other float value.
525       This treatment of nan ensures that compare defines a total ordering re‐
526       lation.
527
528
529
530       val equal : t -> t -> bool
531
532       The   equal   function   for  floating-point  numbers,  compared  using
533       Float.compare .
534
535
536
537       val min : t -> t -> t
538
539
540       min x y returns the minimum of x and y .  It returns nan when x or y is
541       nan .  Moreover min (-0.) (+0.) = -0.
542
543
544
545       Since 4.08.0
546
547
548
549       val max : float -> float -> float
550
551
552       max x y returns the maximum of x and y .  It returns nan when x or y is
553       nan .  Moreover max (-0.) (+0.) = +0.
554
555
556
557       Since 4.08.0
558
559
560
561       val min_max : float -> float -> float * float
562
563
564       min_max x y is (min x y, max x y) , just more efficient.
565
566
567       Since 4.08.0
568
569
570
571       val min_num : t -> t -> t
572
573
574       min_num x y returns the minimum of x and y treating nan as missing val‐
575       ues.   If  both  x  and  y are nan , nan is returned.  Moreover min_num
576       (-0.) (+0.) = -0.
577
578
579
580       Since 4.08.0
581
582
583
584       val max_num : t -> t -> t
585
586
587       max_num x y returns the maximum of x and y treating nan as missing val‐
588       ues.   If both x and y are nan nan is returned.  Moreover max_num (-0.)
589       (+0.) = +0.
590
591
592
593       Since 4.08.0
594
595
596
597       val min_max_num : float -> float -> float * float
598
599
600       min_max_num x y is (min_num x y, max_num x y) ,  just  more  efficient.
601       Note  that in particular min_max_num x nan = (x, x) and min_max_num nan
602       y = (y, y) .
603
604
605       Since 4.08.0
606
607
608
609       val hash : t -> int
610
611       The hash function for floating-point numbers.
612
613
614       module Array : sig end
615
616
617       Float arrays with packed representation.
618
619
620       module ArrayLabels : sig end
621
622
623       Float arrays with packed representation (labeled functions).
624
625
626
627
628
629OCamldoc                          2021-07-22                   Stdlib.Float(3)
Impressum