package hardcaml_fixed_point

  1. Overview
  2. Docs
type bits
module Round : sig ... end
module Overflow : sig ... end
type t
val sexp_of_t : t -> Sexplib0.Sexp.t
val create : int -> bits -> t

create a fixed point value. create f x will have f fractional bits. width x - f will be the number of integer bits

val int : t -> bits

return the integer part of the value

val frac : t -> bits

return the fractional part of the value

val signal : t -> bits

return the underlying bits

val map : t -> f:(bits -> bits) -> t

Map over the internal signal. Useful to register fixed point values

map t ~f:(reg spec ~enable:vdd).

val width_int : t -> int

number of integer bits

val width_frac : t -> int

number of fractional bits

val to_float : t -> float

convert fixed point value to a float

val select_int : t -> int -> bits

select_int f x extracts the integer part, and resizes it to x bits. Bits are dropped from the msb down, if required.

val select_frac : t -> int -> bits

select_frac f x extracts the fractional part, and resizes it to x bits. Bits are dropped from the lsb up, if required.

val select : t -> int -> int -> t

resizes a fixed type using select_int and select_frac

val norm : t list -> t list

find largest integer and fractional parts in each fixed value, and resize all elements to that size

val norm2 : t -> t -> t * t

same as norm, but for 2 values

val of_float : int -> int -> float -> t

create a fixed value with the given number of integer and fractional bits from the floating point value

val (+:) : t -> t -> t

adition

val (-:) : t -> t -> t

subtraction

val (*:) : t -> t -> t

multiplication

val (==:) : t -> t -> bits

equality

val (<>:) : t -> t -> bits

inequality

val (<:) : t -> t -> bits

less than

val (<=:) : t -> t -> bits

less than or equal to

val (>:) : t -> t -> bits

greater than

val (>=:) : t -> t -> bits

greater than or equal to

val mux : bits -> t list -> t

multiplexor

val scale_pow2 : t -> int -> t

scale_pow2 t x will compute t * (2 ^ x), allowing for multiplication or division by a power of 2. Equivalent to a left or right bit shift but also does boundary checking and will extend the underlying number of bits if required.

val resize : ?round:Round.t -> ?overflow:Overflow.t -> t -> int -> int -> t

resize x i f will resize the integer part to have i bits, and fractional part to have f bits. Rounding and overflow control is applied