Abstract

Basic mathematical modules and functions.

Synopsis

module type from_prim = {
type t
val i8: i8 -> t
val i16: i16 -> t
val i32: i32 -> t
val i64: i64 -> t
val u8: u8 -> t
val u16: u16 -> t
val u32: u32 -> t
val u64: u64 -> t
val f32: f32 -> t
val f64: f64 -> t
val bool: bool -> t
}
module type numeric = {
include from_prim
val +: t -> t -> t
val -: t -> t -> t
val *: t -> t -> t
val /: t -> t -> t
val **: t -> t -> t
val to_i64: t -> i64
val ==: t -> t -> bool
val <: t -> t -> bool
val >: t -> t -> bool
val <=: t -> t -> bool
val >=: t -> t -> bool
val !=: t -> t -> bool
val negate: t -> t
val max: t -> t -> t
val min: t -> t -> t
val abs: t -> t
val sgn: t -> t
val highest: t
val lowest: t
val sum: []t -> t
val product: []t -> t
val maximum: []t -> t
val minimum: []t -> t
}
module type integral = {
include numeric
val %: t -> t -> t
val //: t -> t -> t
val %%: t -> t -> t
val &: t -> t -> t
val |: t -> t -> t
val ^: t -> t -> t
val ~: t -> t
val <<: t -> t -> t
val >>: t -> t -> t
val >>>: t -> t -> t
val num_bits: i32
val get_bit: i32 -> t -> i32
val set_bit: i32 -> t -> i32 -> t
}
module type size = {
include integral
val iota: t -> *[]t
val replicate 'v: t -> v -> *[]v
}
module type real = {
include numeric
val from_fraction: i32 -> i32 -> t
val to_i32: t -> i32
val to_i64: t -> i64
val to_f64: t -> f64
val sqrt: t -> t
val exp: t -> t
val cos: t -> t
val sin: t -> t
val tan: t -> t
val asin: t -> t
val acos: t -> t
val atan: t -> t
val atan2: t -> t -> t
val log: t -> t
val log2: t -> t
val log10: t -> t
val ceil: t -> t
val floor: t -> t
val trunc: t -> t
val round: t -> t
val isinf: t -> bool
val isnan: t -> bool
val inf: t
val nan: t
val pi: t
val e: t
}
module type float = {
include real
type int_t
val from_bits: int_t -> t
val to_bits: t -> int_t
val num_bits: i32
val get_bit: i32 -> t -> i32
val set_bit: i32 -> t -> i32 -> t
}
module bool: from_prim with t = bool
module i8: (size with t = i8)
module i16: (size with t = i16)
module i32: (size with t = i32)
module i64: (size with t = i64)
module u8: (size with t = u8)
module u16: (size with t = u16)
module u32: (size with t = u32)
module u64: (size with t = u64)
module f64: (float with t = f64 with int_t = u64)
module f32: (float with t = f32 with int_t = u32)

Description

module type from_prim

Describes types of values that can be created from the primitive numeric types (and bool).

type t
val i8: i8 -> t
val i16: i16 -> t
val i32: i32 -> t
val i64: i64 -> t
val u8: u8 -> t
val u16: u16 -> t
val u32: u32 -> t
val u64: u64 -> t
val f32: f32 -> t
val f64: f64 -> t
val bool: bool -> t
module type numeric

A basic numeric module type that can be implemented for both integers and rational numbers.

include from_prim
val +: t -> t -> t
val -: t -> t -> t
val *: t -> t -> t
val /: t -> t -> t
val **: t -> t -> t
val to_i64: t -> i64
val ==: t -> t -> bool
val <: t -> t -> bool
val >: t -> t -> bool
val <=: t -> t -> bool
val >=: t -> t -> bool
val !=: t -> t -> bool
val negate: t -> t
val max: t -> t -> t
val min: t -> t -> t
val abs: t -> t
val sgn: t -> t
val highest: t

The highest representable number.

val lowest: t

The lowest representable number.

val sum: []t -> t

Returns zero on empty input.

val product: []t -> t

Returns one on empty input.

val maximum: []t -> t

Returns lowest on empty input.

val minimum: []t -> t

Returns highest on empty input.

module type integral

An extension of numeric that provides facilities that are only meaningful for integral types.

include numeric
val %: t -> t -> t
val //: t -> t -> t
val %%: t -> t -> t
val &: t -> t -> t
val |: t -> t -> t
val ^: t -> t -> t
val ~: t -> t
val <<: t -> t -> t
val >>: t -> t -> t
val >>>: t -> t -> t
val num_bits: i32
val get_bit: i32 -> t -> i32
val set_bit: i32 -> t -> i32 -> t
module type size

An extension of size that further includes facilities for constructing arrays where the size is provided as a value of the given integral type.

include integral
val iota: t -> *[]t
val replicate 'v: t -> v -> *[]v
module type real

Numbers that model real numbers to some degree.

include numeric
val from_fraction: i32 -> i32 -> t
val to_i32: t -> i32
val to_i64: t -> i64
val to_f64: t -> f64
val sqrt: t -> t
val exp: t -> t
val cos: t -> t
val sin: t -> t
val tan: t -> t
val asin: t -> t
val acos: t -> t
val atan: t -> t
val atan2: t -> t -> t
val log: t -> t

Natural logarithm.

val log2: t -> t

Base-2 logarithm.

val log10: t -> t

Base-10 logarithm.

val ceil: t -> t
val floor: t -> t
val trunc: t -> t
val round: t -> t

Round to the nearest integer, with alfway cases rounded to the nearest even integer. Note that this differs from round() in C, but matches more modern languages.

val isinf: t -> bool
val isnan: t -> bool
val inf: t
val nan: t
val pi: t
val e: t
module type float

An extension of real that further gives access to the bitwise representation of the underlying number. It is presumed that this will be some form of IEEE float.

include real
type int_t

An unsigned integer type containing the same number of bits as 't'.

val from_bits: int_t -> t
val to_bits: t -> int_t
val num_bits: i32
val get_bit: i32 -> t -> i32
val set_bit: i32 -> t -> i32 -> t
module bool

Boolean numbers. When converting from a number to bool, 0 is considered false and any other value is true.

module i8
module i16
module i32
module i64
module u8
module u16
module u32
module u64
module f64
module f32