|
| 1 | +-- | Wraps the math functions and constants from Javascript's built-in `Math` object. |
1 | 2 | module Math where |
2 | 3 |
|
| 4 | +-- | An alias to make types in this module more explicit. |
3 | 5 | type Radians = Number |
4 | 6 |
|
| 7 | +-- | Returns the absolute value of the argument. |
5 | 8 | foreign import abs "var abs = Math.abs;" :: Number -> Number |
6 | 9 |
|
| 10 | +-- | Returns the arccosine of the argument. |
7 | 11 | foreign import acos "var acos = Math.acos;" :: Number -> Radians |
8 | 12 |
|
| 13 | +-- | Returns the arcsine of the argument. |
9 | 14 | foreign import asin "var asin = Math.asin;" :: Number -> Radians |
10 | 15 |
|
| 16 | +-- | Returns the arctangent of the argument. |
11 | 17 | foreign import atan "var atan = Math.atan;" :: Number -> Radians |
12 | 18 |
|
| 19 | +-- | Four-quadrant tangent inverse. Given `y` and `x`, returns the arctangent of |
| 20 | +-- | `y / x`, where the signs of both arguments are used to determine the sign |
| 21 | +-- | of the result. |
| 22 | +-- | If the first argument is negative, the result will be negative. |
| 23 | +-- | The result is the counterclockwise angle between the positive x axis and |
| 24 | +-- | the point `(x, y)`. |
13 | 25 | foreign import atan2 |
14 | 26 | "function atan2(y){\ |
15 | 27 | \ return function (x) {\ |
16 | 28 | \ return Math.atan2(y, x);\ |
17 | 29 | \ };\ |
18 | 30 | \}" :: Number -> Number -> Radians |
19 | 31 |
|
| 32 | +-- | Returns the smallest integer greater than or equal to the argument. |
20 | 33 | foreign import ceil "var ceil = Math.ceil;" :: Number -> Number |
21 | 34 |
|
| 35 | +-- | Returns the cosine of the argument. |
22 | 36 | foreign import cos "var cos = Math.cos;" :: Radians -> Number |
23 | 37 |
|
| 38 | +-- | Returns `e` exponentiated to the power of the argument. |
24 | 39 | foreign import exp "var exp = Math.exp;" :: Number -> Number |
25 | 40 |
|
| 41 | +-- | Returns the largest integer less than or equal to the argument. |
26 | 42 | foreign import floor "var floor = Math.floor;" :: Number -> Number |
27 | 43 |
|
| 44 | +-- | Returns the natural logarithm of a number. |
28 | 45 | foreign import log "var log = Math.log;" :: Number -> Number |
29 | 46 |
|
| 47 | +-- | Returns the largest of two numbers. |
30 | 48 | foreign import max |
31 | 49 | "function max(n1){\ |
32 | 50 | \ return function(n2) {\ |
33 | 51 | \ return Math.max(n1, n2);\ |
34 | 52 | \ }\ |
35 | 53 | \}" :: Number -> Number -> Number |
36 | 54 |
|
| 55 | +-- | Returns the smallest of two numbers. |
37 | 56 | foreign import min |
38 | 57 | "function min(n1){\ |
39 | 58 | \ return function(n2) {\ |
40 | 59 | \ return Math.min(n1, n2);\ |
41 | 60 | \ }\ |
42 | 61 | \}" :: Number -> Number -> Number |
43 | 62 |
|
| 63 | +-- | Return the first argument exponentiated to the power of the second argument. |
44 | 64 | foreign import pow |
45 | 65 | "function pow(n){\ |
46 | 66 | \ return function(p) {\ |
47 | 67 | \ return Math.pow(n, p);\ |
48 | 68 | \ }\ |
49 | 69 | \}" :: Number -> Number -> Number |
50 | 70 |
|
| 71 | +-- | Returns the integer nearest to the argument. |
51 | 72 | foreign import round "var round = Math.round;" :: Number -> Number |
52 | 73 |
|
| 74 | +-- | Returns the sine of the argument. |
53 | 75 | foreign import sin "var sin = Math.sin;" :: Radians -> Number |
54 | 76 |
|
| 77 | +-- | Returns the square root of the argument. |
55 | 78 | foreign import sqrt "var sqrt = Math.sqrt;" :: Number -> Number |
56 | 79 |
|
| 80 | +-- | Returns the tangent of the argument. |
57 | 81 | foreign import tan "var tan = Math.tan;" :: Radians -> Number |
58 | 82 |
|
| 83 | +-- | Euler's constant and the base of natural logarithms, approximately 2.718. |
59 | 84 | foreign import e "var e = Math.E;" :: Number |
| 85 | + |
| 86 | +-- | Natural logarithm of 2, approximately 0.693. |
60 | 87 | foreign import ln2 "var ln2 = Math.LN2;" :: Number |
| 88 | + |
| 89 | +-- | Natural logarithm of 10, approximately 2.303. |
61 | 90 | foreign import ln10 "var ln10 = Math.LN10;" :: Number |
| 91 | + |
| 92 | +-- | Base 2 logarithm of `e`, approximately 1.443. |
62 | 93 | foreign import log2e "var log2e = Math.LOG2E;" :: Number |
| 94 | + |
| 95 | +-- | Base 10 logarithm of `e`, approximately 0.434. |
63 | 96 | foreign import log10e "var log10e = Math.LOG10E;" :: Number |
| 97 | + |
| 98 | +-- | Ratio of the circumference of a circle to its diameter, approximately 3.14159. |
64 | 99 | foreign import pi "var pi = Math.PI;" :: Number |
| 100 | + |
| 101 | +-- | Square root of 1/2, approximately 0.707. |
65 | 102 | foreign import sqrt1_2 "var sqrt1_2 = Math.SQRT1_2;" :: Number |
| 103 | + |
| 104 | +-- | Square root of 2, approximately 1.414. |
66 | 105 | foreign import sqrt2 "var sqrt2 = Math.SQRT2;" :: Number |
0 commit comments