Module CCFloatSource

Basic operations on floating-point numbers

Sourcetype t = float
Sourcetype fpclass = CCShims_.Stdlib.fpclass =
  1. | FP_normal
  2. | FP_subnormal
  3. | FP_zero
  4. | FP_infinite
  5. | FP_nan
Sourceval nan : t

Equal to Stdlib.nan.

Sourceval max_value : t

Positive infinity. Equal to Stdlib.infinity.

Sourceval min_value : t

Negative infinity. Equal to Stdlib.neg_infinity.

Sourceval max_finite_value : t
Sourceval epsilon : t

The smallest positive float x such that 1.0 +. x <> 1.0. Equal to Stdlib.epsilon_float.

Sourceval is_nan : t -> bool

is_nan f returns true if f is NaN, false otherwise.

Sourceval add : t -> t -> t

Equal to (+.).

Sourceval sub : t -> t -> t

Equal to (-.).

Sourceval neg : t -> t

Equal to (~-.).

Sourceval abs : t -> t

The absolute value of a floating-point number. Equal to Stdlib.abs_float.

Sourceval scale : t -> t -> t

Equal to ( *. ).

Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval equal : t -> t -> bool
Sourceval compare : t -> t -> int
Sourcetype 'a printer = Format.formatter -> 'a -> unit
Sourcetype 'a random_gen = Random.State.t -> 'a
Sourceval pp : t printer
Sourceval hash : t -> int
Sourceval random : t -> t random_gen
Sourceval random_small : t random_gen
Sourceval random_range : t -> t -> t random_gen
Sourceval fsign : t -> t

fsign x is one of -1., -0., +0., +1., or nan if x is NaN.

  • since 0.7
Sourceval round : t -> t

round f returns the closest integer value, either above or below.

  • since 0.20
Sourceexception TrapNaN of string
Sourceval sign_exn : t -> int

sign_exn x will return the sign of x as 1, 0 or -1, or raise an exception TrapNaN if x is NaN. Note that infinities have defined signs in OCaml.

  • since 0.7
Sourceval to_int : t -> int

Alias to int_of_float. Unspecified if outside of the range of integers.

Sourceval of_int : int -> t

Alias to float_of_int.

Sourceval to_string : t -> string
Sourceval of_string_exn : string -> t

Alias to float_of_string.

  • since 1.2
Sourceval of_string : string -> t
  • deprecated use of_string_exn instead
Sourceval equal_precision : epsilon:t -> t -> t -> bool

Equality with allowed error up to a non negative epsilon value.

Sourceval classify : t -> fpclass

Return the class of the given floating-point number: normal, subnormal, zero, infinite or nan (not a number).

Infix Operators

Sourcemodule Infix : sig ... end
include module type of Infix
Sourceval (=) : t -> t -> bool
  • since 0.17
Sourceval (<>) : t -> t -> bool
  • since 0.17
Sourceval (<) : t -> t -> bool
  • since 0.17
Sourceval (>) : t -> t -> bool
  • since 0.17
Sourceval (<=) : t -> t -> bool
  • since 0.17
Sourceval (>=) : t -> t -> bool
  • since 0.17
Sourceval (+) : t -> t -> t

Addition.

  • since 2.1
Sourceval (-) : t -> t -> t

Subtraction.

  • since 2.1
Sourceval (~-) : t -> t

Unary negation.

  • since 2.1
Sourceval (*) : t -> t -> t

Multiplication.

  • since 2.1
Sourceval (/) : t -> t -> t

Division.

  • since 2.1