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