|
| 1 | +-- | Wraps the math functions and constants from Javascript's built-in `Math` object. |
| 2 | +-- | See [Math Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). |
1 | 3 | module Math where |
2 | 4 |
|
| 5 | +-- | An alias to make types in this module more explicit. |
3 | 6 | type Radians = Number |
4 | 7 |
|
| 8 | +-- | Returns the absolute value of the argument. |
5 | 9 | foreign import abs "var abs = Math.abs;" :: Number -> Number |
6 | 10 |
|
| 11 | +-- | Returns the inverse cosine of the argument. |
7 | 12 | foreign import acos "var acos = Math.acos;" :: Number -> Radians |
8 | 13 |
|
| 14 | +-- | Returns the inverse sine of the argument. |
9 | 15 | foreign import asin "var asin = Math.asin;" :: Number -> Radians |
10 | 16 |
|
| 17 | +-- | Returns the inverse tangent of the argument. |
11 | 18 | foreign import atan "var atan = Math.atan;" :: Number -> Radians |
12 | 19 |
|
| 20 | +-- | Four-quadrant tangent inverse. Given the arguments `y` and `x`, returns |
| 21 | +-- | the inverse tangent of `y / x`, where the signs of both arguments are used |
| 22 | +-- | to determine the sign of the result. |
| 23 | +-- | If the first argument is negative, the result will be negative. |
| 24 | +-- | The result is the angle between the positive x axis and a 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 not smaller than 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 not larger than 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 closest 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 | +-- | The base of natural logarithms, *e*, around 2.71828. |
59 | 84 | foreign import e "var e = Math.E;" :: Number |
| 85 | + |
| 86 | +-- | The natural logarithm of 2, around 0.6931. |
60 | 87 | foreign import ln2 "var ln2 = Math.LN2;" :: Number |
| 88 | + |
| 89 | +-- | The natural logarithm of 10, around 2.3025. |
61 | 90 | foreign import ln10 "var ln10 = Math.LN10;" :: Number |
| 91 | + |
| 92 | +-- | The base 2 logarithm of `e`, around 1.4426. |
62 | 93 | foreign import log2e "var log2e = Math.LOG2E;" :: Number |
| 94 | + |
| 95 | +-- | Base 10 logarithm of `e`, around 0.43429. |
63 | 96 | foreign import log10e "var log10e = Math.LOG10E;" :: Number |
| 97 | + |
| 98 | +-- | The ratio of the circumference of a circle to its diameter, around 3.14159. |
64 | 99 | foreign import pi "var pi = Math.PI;" :: Number |
| 100 | + |
| 101 | +-- | The Square root of one half, around 0.707107. |
65 | 102 | foreign import sqrt1_2 "var sqrt1_2 = Math.SQRT1_2;" :: Number |
| 103 | + |
| 104 | +-- | The square root of two, around 1.41421. |
66 | 105 | foreign import sqrt2 "var sqrt2 = Math.SQRT2;" :: Number |
0 commit comments