SML3d
3d graphics for Standard ML
  signature C_ALLOC
  signature C_OBJECT
  signature C_STRING
  signature DATA_BUFFER
  signature SCALAR
  signature FP
  signature IMAGE
  structure CAlloc : C_Alloc
  structure CObject : C_Object
  structure CString : C_String

  structure Float : SCALAR
  structure Double : SCALAR
  structure FP : FP

  structure DataBuffer : DATA_BUFFER

  structure Image : IMAGE
  structure ImageUtil

The SCALAR signature

The SCALAR signature defines a collection of useful constants and operations on floating-point numbers.

signature SCALAR =
  sig

    structure Rep : REAL	(* the underlying SML Real representation *)

    type t = Rep.real

    val epsilon : t		(* small value close to zero *)

    val M_E : t			(* base of natural logarithm, e *)
    val M_LOG2E : t		(* log2(e) *)
    val M_LOG10E : t		(* log10(e) *)
    val M_LN2 : t		(* ln(2) *)
    val M_LN10 : t		(* ln(10) *)
    val M_PI : t		(* pi *)
    val M_PI_2 : t		(* pi / 2 *)
    val M_PI_4 : t		(* pi / 4 *)
    val M_1_PI : t		(* 1 / pi *)
    val M_2_PI : t		(* 2 / pi *)
    val M_2_SQRTPI : t		(* 2 / sqrt(pi) *)
    val M_SQRT2 : t		(* sqrt(2) *)
    val M_SQRT1_2 : t		(* sqrt(1/2) *)

    val M_POS_INF : t		(* +infinity *)
    val M_NEG_INF : t		(* -infinity *)

    val abs : t -> t
    val min : t * t -> t
    val max : t * t -> t

  (* utility *)
    val clip  : {min : t, max : t} -> t -> t
    val clamp : t -> t		(* clamp to [0..1] *)
    val lerp : (t * t * t) -> t
    val smoothStep : t -> t		(* 3 t^2 - 2 t^3; 0 <= t <= 1 *)

  (* math functions *)
    val sqrt : t -> t
    val sin : t -> t
    val cos : t -> t
    val tan : t -> t
    val asin : t -> t
    val acos : t -> t
    val atan : t -> t
    val atan2 : t * t -> t
    val exp : t -> t
    val pow : t * t -> t
    val ln : t -> t
    val log10 : t -> t
    val sinh : t -> t
    val cosh : t -> t
    val tanh : t -> t

  (* conversions to/from radians *)
    val toRadians : t -> t
    val toDegrees : t -> t

  (* integer conversions *)
    val fromInt : Int32.int -> t
    val fromLong : Int64.int -> t
    val roundToInt : t -> Int32.int

  (* rounding *)
    val frac  : t -> t (* fractional part *)
    val trunc : t -> t
    val round : t -> t
    val floor : t -> t
    val ceil  : t -> t

  (* split into whole/fractional parts *)
    val split : t -> {whole : t, frac : t}

  (* string conversions *)
    val fromString : string -> t option
    val toString : t -> string

  end

Substructures

Types

  • t

    the scalar type defined by the instance of the signature.

Values

Constants

Comparisons

Math functions

  • sqrt x

    returns the square root of x.

  • sin x

    returns the sine of x (measured in radians).

  • cos x

    returns the cosine of x (measured in radians).

  • tan x

    returns the tangent of x (measured in radians).

  • asin x

    returns an angle whose sine is x in the range [-pi/2,pi/2].

  • acos x

    returns an angle whose cosine is x in the range [-pi/2,pi/2].

  • atan x

    returns an angle in the range [-pi/2,pi/2] whose tangent is x.

  • atan2 (y, x)

    returns an angle in the range [-pi,pi] whose tangent is y/x. The quadrent of the nagle is determined by the signs of x and y.

  • sinh x

    returns the hyperbolic sine of x.

  • cosh x

    returns the hyperbolic cosine of x.

  • tanh x

    returns the hyperbolic tangent of x.

  • exp x

    returns e^x.

  • pow (x, y)

    returns x^y.

  • ln x

    returns the natural logarithm of x.

  • log10 x

    returns the base-10 logarithm of x.

Conversions

Rounding

Instances

The SML3d Library provides two implementations of the SCALAR signature; one for IEEE single-precision numbers and one for IEEE double-precision numbers:

structure Float : SCALAR
structure Double : SCALAR