package affect

  1. Overview
  2. Docs

Module Mtime.SpanSource

Time spans.

Time spans

Sourcetype t

The type for non-negative monotonic time spans.

They represent the difference between two monotonic clock readings with nanosecond precision (1e-9s) and can measure up to approximatevely 584 Julian year spans before silently rolling over (unlikely since this is in a single program run).

Sourceval zero : t

zero is a span of 0ns.

Sourceval one : t

one is a span of 1ns.

Sourceval max_span : t

max_span is a span of 2^64-1ns.

Sourceval add : t -> t -> t

add s s' is s + s'. Warning. Rolls over on overflow.

Sourceval abs_sub : t -> t -> t

abs_sub s s' |s - s'| is the absolute difference between s0 and s1.

Sourceval sat_sub : t -> t -> t

sat_sub s s' is s - s' and floors at zero.

Predicates and comparisons

Sourceval equal : t -> t -> bool

equal s0 s1 is true if and only if s0 is equal to s1.

Sourceval compare : t -> t -> int

compare totally orders spans by increasing duration.

Sourceval is_shorter : t -> than:t -> bool

is_shorter span ~than is true if and only if span lasts stricly less than than.

Sourceval is_longer : t -> than:t -> bool

is_longer span ~than is true if and only if span lasts stricly more than than.

Durations

Sourceval (*) : int -> t -> t

n * dur is n times duration dur. Does not check for overflow or that n is positive.

Sourceval (/) : t -> int -> t

dur / n is duration dur divided by n. Does not check for that n is positive, rounds towards 0.

Sourceval (+) : t -> t -> t

s + s' is s + s'. Warning. Rolls over on overflow.

Sourceval (-) : t -> t -> t

s - s' is sat_sub s s', floors at zero.

Sourceval ns : t

ns is a nanosecond duration, 1·10-9s.

Sourceval us : t

us is a microsecond duration, 1·10-6s.

Sourceval ms : t

ms is a millisecond duration, 1·10-3s.

Sourceval s : t

s is a second duration, 1s.

Sourceval min : t

min is a minute duration, 60s.

Sourceval hour : t

hour is an hour duration, 3600s.

Sourceval day : t

day is a day duration, 86'400s.

Sourceval year : t

year is a Julian year duration (365.25 days), 31'557'600s.

Conversions

Sourceval to_uint64_ns : t -> int64

to_uint64_ns span is span as an unsigned 64-bit integer nanosecond span.

Sourceval of_uint64_ns : int64 -> t

of_uint64_ns u is the unsigned 64-bit integer nanosecond span u as a span.

Sourceval of_float_ns : float -> t option

of_float_ns f is the positive floating point nanosecond span f as a span. This is None if f is negative, non finite, or larger or equal than 253 (~104 days, the largest exact floating point integer).

Sourceval to_float_ns : t -> float

to_float_ns span is span as a nanosecond floating point span. Note that if span is larger than 253 (~104 days, the largest exact floating point integer) the result is an approximation and will not round trip with of_float_ns.

Sourceval to_float_s : t -> float

to_float_s span is 1e9 * to_float_ns span.

Sourceval of_float_s : float -> t option

of_float_s f is of_float_ns (f *. 1e9)

Formatting

Note. The fmt library has Fmt.uint64_ns_span for actual prettyness.

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

pp formats with Fmt.uint64_ns_span.

Sourceval pp_ns : Format.formatter -> t -> unit

pp_ns ppf s prints s as an unsigned 64-bit integer nanosecond span.