2011-10-26 13:28:23 -05:00
|
|
|
/* Module: math */
|
|
|
|
|
2011-11-16 22:49:38 -06:00
|
|
|
#[link_name = ""]
|
|
|
|
#[abi = "cdecl"]
|
|
|
|
native mod libc {
|
2011-11-07 17:29:05 -06:00
|
|
|
fn sqrt(n: float) -> float;
|
|
|
|
fn sin(n: float) -> float;
|
|
|
|
fn asin(n: float) -> float;
|
|
|
|
fn cos(n: float) -> float;
|
|
|
|
fn acos(n: float) -> float;
|
|
|
|
fn tan(n: float) -> float;
|
|
|
|
fn atan(n: float) -> float;
|
2011-11-20 11:44:37 -06:00
|
|
|
#[link_name="log"]
|
|
|
|
fn ln(n: float) -> float;
|
|
|
|
fn log2(n: float) -> float;
|
|
|
|
fn log10(n: float) -> float;
|
|
|
|
fn log1p(n: float) -> float;
|
2011-10-18 06:45:17 -05:00
|
|
|
}
|
|
|
|
|
2011-10-26 18:24:31 -05:00
|
|
|
/*
|
|
|
|
Function: sqrt
|
|
|
|
|
|
|
|
Returns the square root
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn sqrt(x: float) -> float { unsafe { libc::sqrt(x) } }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: sin
|
|
|
|
|
|
|
|
Returns the sine of an angle
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn sin(x: float) -> float { unsafe { libc::sin(x) } }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: cos
|
|
|
|
|
|
|
|
Returns the cosine of an angle
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn cos(x: float) -> float { unsafe { libc::cos(x) } }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: tan
|
|
|
|
|
|
|
|
Returns the tangent of an angle
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn tan(x: float) -> float { unsafe { libc::tan(x) } }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: asin
|
|
|
|
|
|
|
|
Returns the arcsine of an angle
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn asin(x: float) -> float { unsafe { libc::asin(x) } }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: acos
|
|
|
|
|
|
|
|
Returns the arccosine of an angle
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn acos(x: float) -> float { unsafe { libc::acos(x) } }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: atan
|
|
|
|
|
|
|
|
Returns the arctangent of an angle
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn atan(x: float) -> float { unsafe { libc::atan(x) } }
|
2011-10-18 06:45:17 -05:00
|
|
|
|
2011-10-26 18:24:31 -05:00
|
|
|
/*
|
|
|
|
Const: pi
|
|
|
|
|
|
|
|
Archimedes' constant
|
|
|
|
*/
|
2011-10-18 06:45:17 -05:00
|
|
|
const pi: float = 3.141592653589793;
|
|
|
|
|
2011-10-26 18:24:31 -05:00
|
|
|
/*
|
|
|
|
Function: min
|
|
|
|
|
|
|
|
Returns the minimum of two values
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn min<copy T>(x: T, y: T) -> T { x < y ? x : y }
|
2011-10-26 18:24:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: max
|
|
|
|
|
|
|
|
Returns the maximum of two values
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn max<copy T>(x: T, y: T) -> T { x < y ? y : x }
|
2011-11-20 11:44:37 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
Const: e
|
|
|
|
|
|
|
|
Euler's number
|
|
|
|
*/
|
|
|
|
const e: float = 2.718281828459045235;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: ln
|
|
|
|
|
|
|
|
Returns the natural logaritm
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn ln(n: float) -> float { unsafe { libc::ln(n) } }
|
2011-11-20 11:44:37 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: log2
|
|
|
|
|
|
|
|
Returns the logarithm to base 2
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn log2(n: float) -> float { unsafe { libc::log2(n) } }
|
2011-11-20 11:44:37 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: log2
|
|
|
|
|
|
|
|
Returns the logarithm to base 10
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn log10(n: float) -> float { unsafe { libc::log10(n) } }
|
2011-11-20 11:44:37 -06:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: log1p
|
|
|
|
|
2011-11-20 19:01:36 -06:00
|
|
|
Returns the natural logarithm of `1+n` accurately,
|
2011-11-20 11:44:37 -06:00
|
|
|
even for very small values of `n`
|
|
|
|
*/
|
2011-11-20 19:01:36 -06:00
|
|
|
pure fn ln1p(n: float) -> float { unsafe { libc::log1p(n) } }
|