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

# SCM Repository

[sml3d] View of /src/common/double.sml
 [sml3d] / src / common / double.sml

# View of /src/common/double.sml

Mon Mar 10 19:45:51 2008 UTC (11 years, 10 months ago) by jhr
File size: 3097 byte(s)
```  Fix type errors
```
```(* double.sml
*
* COPYRIGHT (c) 2008 John Reppy (http://www.cs.uchicago.edu/~jhr)
*
* Double-precision floating-point numbers.
*)

structure Double : sig

type double = SML3dTypes.double

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

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

val toRadians : double -> double
val toDegrees : double -> double

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

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

end = struct

type double = SML3dTypes.double

open Real64.Math

val M_E : double		= 2.71828182845904523536028747135266250   (* e *)
val M_LOG2E : double	= 1.44269504088896340735992468100189214   (* log 2e *)
val M_LOG10E : double 	= 0.434294481903251827651128918916605082  (* log 10e *)
val M_LN2 : double		= 0.693147180559945309417232121458176568  (* log e2 *)
val M_LN10 : double		= 2.30258509299404568401799145468436421   (* log e10 *)
val M_PI : double		= 3.14159265358979323846264338327950288   (* pi *)
val M_PI_2 : double		= 1.57079632679489661923132169163975144   (* pi/2 *)
val M_PI_4 : double		= 0.785398163397448309615660845819875721  (* pi/4 *)
val M_1_PI : double		= 0.318309886183790671537767526745028724  (* 1/pi *)
val M_2_PI : double		= 0.636619772367581343075535053490057448  (* 2/pi *)
val M_2_SQRTPI : double	= 1.12837916709551257389615890312154517   (* 2/sqrt(pi) *)
val M_SQRT2 : double	= 1.41421356237309504880168872420969808   (* sqrt(2) *)
val M_SQRT1_2 : double	= 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
end (* local *)

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

end
```