package timedesc

  1. Overview
  2. Docs

Module Timedesc.SpanSource

Sourcetype t

Signed/directional span of time with nanosecond precision

Sourceexception Out_of_range

Constants

Sourceval ns_count_in_s : int
Sourceval ns_count_in_s_float : float
Sourceval zero : t

Constructors

Sourceval make : ?s:int64 -> ?ns:int -> unit -> t

s defaults to 0L, ns defaults to 0.

ns may be negative, and is normalized during construction.

Interpretation of provided input is still s + ns, i.e. if you wish to represent "negative (1 second and 500 nanosecond)", then the call could look like make ~s:(-1L) ~ns:(-500).

  • raises Out_of_range

    if the value cannot be represented even after normalization

Sourceval make_small : ?s:int -> ?ns:int -> unit -> t

Wrapper around make

Conversion

Sourceval to_s_ns : t -> int64 * int

Yields pair (s, ns) where

  • s is the signed second of the span
  • ns is the unsigned nanosecond offset

The actual span represented is defined as s * 10^9 + ns in nanosecond regardless of the sign of s.

ns is always >= 0 and < 1_000_000_000.

Sourceval to_float_s : t -> float

Returns span in seconds, fraction represents subsecond span.

Representation is the same as result from Unix.gettimeofday.

Sourceval of_float_s : float -> t

Convert from span in seconds, fraction represents subsecond span

Representation is the same as result from Unix.gettimeofday.

Accessors

Sourceval get_s : t -> int64

Yields signed second of span, same as fst (to_s_ns _)

Sourceval get_ns_offset : t -> int

Yields the unsigned nanosecond offset, same as snd (to_s_ns _)

Comparison

Sourceval equal : t -> t -> bool
Sourceval lt : t -> t -> bool
Sourceval le : t -> t -> bool
Sourceval gt : t -> t -> bool
Sourceval ge : t -> t -> bool
Sourceval compare : t -> t -> int

Arithmetic

Sourceval add : t -> t -> t
Sourceval sub : t -> t -> t
Sourceval succ : t -> t
Sourceval pred : t -> t
Sourceval neg : t -> t
Sourceval abs : t -> t
Sourceval max : t -> t -> t
Sourceval min : t -> t -> t
Sourceval ceil : t -> t

Rounds up to nearest second

Sourceval floor : t -> t

Rounds down to nearest second

Sourceval round : t -> t

Rounds to nearest second

For round x

  • if x.ns >= 500_000_000, then round x = ceil x
  • otherwise round x = floor x
Sourceval (<) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (>=) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval (-) : t -> t -> t
Sourceval (+) : t -> t -> t

Pretty printing

Sourceval to_string : t -> string
Sourceval pp : Format.formatter -> t -> unit

Sexp

Sourceval to_sexp : t -> CCSexp.t
Sourceval to_sexp_string : t -> string
Sourceval of_sexp : CCSexp.t -> (t, string) result
Sourceval of_sexp_string : string -> (t, string) result
Sourceval pp_sexp : Format.formatter -> t -> unit

Human friendly APIs

Sourcemodule For_human : sig ... end
OCaml

Innovation. Community. Security.