Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /src/common/float.sml
ViewVC logotype

View of /src/common/float.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (download) (annotate)
Mon Mar 10 19:45:51 2008 UTC (11 years, 10 months ago) by jhr
File size: 3012 byte(s)
  Fix type errors
(* float.sml
 *
 * COPYRIGHT (c) 2008 John Reppy (http://www.cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * Single-precision floating-point numbers.
 *)

structure Float : sig

    type float = SML3dTypes.float

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

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

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

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

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

  end = struct

    type float = SML3dTypes.float

    open Real32.Math

    val M_E : float	= 2.71828182845904523536028747135266250   (* e *)
    val M_LOG2E : float	= 1.44269504088896340735992468100189214   (* log 2e *)
    val M_LOG10E : float = 0.434294481903251827651128918916605082  (* log 10e *)
    val M_LN2 : float	= 0.693147180559945309417232121458176568  (* log e2 *)
    val M_LN10 : float	= 2.30258509299404568401799145468436421   (* log e10 *)
    val M_PI : float	= 3.14159265358979323846264338327950288   (* pi *)
    val M_PI_2 : float	= 1.57079632679489661923132169163975144   (* pi/2 *)
    val M_PI_4 : float	= 0.785398163397448309615660845819875721  (* pi/4 *)
    val M_1_PI : float	= 0.318309886183790671537767526745028724  (* 1/pi *)
    val M_2_PI : float	= 0.636619772367581343075535053490057448  (* 2/pi *)
    val M_2_SQRTPI : float = 1.12837916709551257389615890312154517   (* 2/sqrt(pi) *)
    val M_SQRT2 : float	= 1.41421356237309504880168872420969808   (* sqrt(2) *)
    val M_SQRT1_2 : float = 0.707106781186547524400844362104849039  (* 1/sqrt(2) *)

    val abs = Real32.abs
    val min = Real32.min
    val max = Real32.max
  
    local
      val m_pi_180 = M_PI / 180.0
      val m_180_Pi = 180.0 * M_1_PI
    in
    fun toRadians deg = m_pi_180 * deg
    fun toDegrees rad = m_180_Pi * rad
    end (* local *)

  (* string conversions *)
    val fromString = Real32.fromString
    val toString = Real32.toString

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0