about summary refs log tree commit diff
path: root/src/lib/math.rs
blob: fe33b133a86c02686454ae13409d8b92ae5eaa72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Module: math */

native "cdecl" mod libc = "" {
    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;
}

/*
Function: sqrt

Returns the square root
*/
fn sqrt(x: float) -> float { libc::sqrt(x) }

/*
Function: sin

Returns the sine of an angle
*/
fn sin(x: float) -> float { libc::sin(x) }

/*
Function: cos

Returns the cosine of an angle
*/
fn cos(x: float) -> float { libc::cos(x) }

/*
Function: tan

Returns the tangent of an angle
*/
fn tan(x: float) -> float { libc::tan(x) }

/*
Function: asin

Returns the arcsine of an angle
*/
fn asin(x: float) -> float { libc::asin(x) }

/*
Function: acos

Returns the arccosine of an angle
*/
fn acos(x: float) -> float { libc::acos(x) }

/*
Function: atan

Returns the arctangent of an angle
*/
fn atan(x: float) -> float { libc::atan(x) }

/*
Const: pi

Archimedes' constant
*/
const pi: float = 3.141592653589793;

/*
Function: min

Returns the minimum of two values
*/
fn min<T>(x: T, y: T) -> T { x < y ? x : y }

/*
Function: max

Returns the maximum of two values
*/
fn max<T>(x: T, y: T) -> T { x < y ? y : x }