Skip to content
This repository was archived by the owner on Jun 5, 2022. It is now read-only.

Commit d2e12e0

Browse files
committed
Merge pull request #3 from brainrape/add-docs
add docs
2 parents c6f15a6 + 69b4a4f commit d2e12e0

File tree

2 files changed

+229
-28
lines changed

2 files changed

+229
-28
lines changed

README.md

+190-28
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,221 @@
22

33
## Module Math
44

5-
### Types
65

7-
type Radians = Number
6+
Wraps the math functions and constants from Javascript's built-in `Math` object.
7+
See [Math Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math).
88

9+
#### `Radians`
910

10-
### Values
11+
``` purescript
12+
type Radians = Number
13+
```
1114

12-
abs :: Number -> Number
15+
An alias to make types in this module more explicit.
1316

14-
acos :: Number -> Radians
17+
#### `abs`
1518

16-
asin :: Number -> Radians
19+
``` purescript
20+
abs :: Number -> Number
21+
```
1722

18-
atan :: Number -> Radians
23+
Returns the absolute value of the argument.
1924

20-
atan2 :: Number -> Number -> Radians
25+
#### `acos`
2126

22-
ceil :: Number -> Number
27+
``` purescript
28+
acos :: Number -> Radians
29+
```
2330

24-
cos :: Radians -> Number
31+
Returns the inverse cosine of the argument.
2532

26-
e :: Number
33+
#### `asin`
2734

28-
exp :: Number -> Number
35+
``` purescript
36+
asin :: Number -> Radians
37+
```
2938

30-
floor :: Number -> Number
39+
Returns the inverse sine of the argument.
3140

32-
ln10 :: Number
41+
#### `atan`
3342

34-
ln2 :: Number
43+
``` purescript
44+
atan :: Number -> Radians
45+
```
3546

36-
log :: Number -> Number
47+
Returns the inverse tangent of the argument.
3748

38-
log10e :: Number
49+
#### `atan2`
3950

40-
log2e :: Number
51+
``` purescript
52+
atan2 :: Number -> Number -> Radians
53+
```
4154

42-
max :: Number -> Number -> Number
55+
Four-quadrant tangent inverse. Given the arguments `y` and `x`, returns
56+
the inverse tangent of `y / x`, where the signs of both arguments are used
57+
to determine the sign of the result.
58+
If the first argument is negative, the result will be negative.
59+
The result is the angle between the positive x axis and a point `(x, y)`.
4360

44-
min :: Number -> Number -> Number
61+
#### `ceil`
4562

46-
pi :: Number
63+
``` purescript
64+
ceil :: Number -> Number
65+
```
4766

48-
pow :: Number -> Number -> Number
67+
Returns the smallest integer not smaller than the argument.
4968

50-
round :: Number -> Number
69+
#### `cos`
5170

52-
sin :: Radians -> Number
71+
``` purescript
72+
cos :: Radians -> Number
73+
```
5374

54-
sqrt :: Number -> Number
75+
Returns the cosine of the argument.
76+
77+
#### `exp`
78+
79+
``` purescript
80+
exp :: Number -> Number
81+
```
82+
83+
Returns `e` exponentiated to the power of the argument.
84+
85+
#### `floor`
86+
87+
``` purescript
88+
floor :: Number -> Number
89+
```
90+
91+
Returns the largest integer not larger than the argument.
92+
93+
#### `log`
94+
95+
``` purescript
96+
log :: Number -> Number
97+
```
98+
99+
Returns the natural logarithm of a number.
100+
101+
#### `max`
102+
103+
``` purescript
104+
max :: Number -> Number -> Number
105+
```
106+
107+
Returns the largest of two numbers.
108+
109+
#### `min`
110+
111+
``` purescript
112+
min :: Number -> Number -> Number
113+
```
114+
115+
Returns the smallest of two numbers.
116+
117+
#### `pow`
118+
119+
``` purescript
120+
pow :: Number -> Number -> Number
121+
```
122+
123+
Return the first argument exponentiated to the power of the second argument.
124+
125+
#### `round`
126+
127+
``` purescript
128+
round :: Number -> Number
129+
```
130+
131+
Returns the integer closest to the argument.
132+
133+
#### `sin`
134+
135+
``` purescript
136+
sin :: Radians -> Number
137+
```
138+
139+
Returns the sine of the argument.
140+
141+
#### `sqrt`
142+
143+
``` purescript
144+
sqrt :: Number -> Number
145+
```
146+
147+
Returns the square root of the argument.
148+
149+
#### `tan`
150+
151+
``` purescript
152+
tan :: Radians -> Number
153+
```
154+
155+
Returns the tangent of the argument.
156+
157+
#### `e`
158+
159+
``` purescript
160+
e :: Number
161+
```
162+
163+
The base of natural logarithms, *e*, around 2.71828.
164+
165+
#### `ln2`
166+
167+
``` purescript
168+
ln2 :: Number
169+
```
170+
171+
The natural logarithm of 2, around 0.6931.
172+
173+
#### `ln10`
174+
175+
``` purescript
176+
ln10 :: Number
177+
```
178+
179+
The natural logarithm of 10, around 2.3025.
180+
181+
#### `log2e`
182+
183+
``` purescript
184+
log2e :: Number
185+
```
186+
187+
The base 2 logarithm of `e`, around 1.4426.
188+
189+
#### `log10e`
190+
191+
``` purescript
192+
log10e :: Number
193+
```
194+
195+
Base 10 logarithm of `e`, around 0.43429.
196+
197+
#### `pi`
198+
199+
``` purescript
200+
pi :: Number
201+
```
202+
203+
The ratio of the circumference of a circle to its diameter, around 3.14159.
204+
205+
#### `sqrt1_2`
206+
207+
``` purescript
208+
sqrt1_2 :: Number
209+
```
210+
211+
The Square root of one half, around 0.707107.
212+
213+
#### `sqrt2`
214+
215+
``` purescript
216+
sqrt2 :: Number
217+
```
218+
219+
The square root of two, around 1.41421.
55220

56-
sqrt1_2 :: Number
57221

58-
sqrt2 :: Number
59222

60-
tan :: Radians -> Number

src/Math.purs

+39
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,105 @@
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).
13
module Math where
24

5+
-- | An alias to make types in this module more explicit.
36
type Radians = Number
47

8+
-- | Returns the absolute value of the argument.
59
foreign import abs "var abs = Math.abs;" :: Number -> Number
610

11+
-- | Returns the inverse cosine of the argument.
712
foreign import acos "var acos = Math.acos;" :: Number -> Radians
813

14+
-- | Returns the inverse sine of the argument.
915
foreign import asin "var asin = Math.asin;" :: Number -> Radians
1016

17+
-- | Returns the inverse tangent of the argument.
1118
foreign import atan "var atan = Math.atan;" :: Number -> Radians
1219

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)`.
1325
foreign import atan2
1426
"function atan2(y){\
1527
\ return function (x) {\
1628
\ return Math.atan2(y, x);\
1729
\ };\
1830
\}" :: Number -> Number -> Radians
1931

32+
-- | Returns the smallest integer not smaller than the argument.
2033
foreign import ceil "var ceil = Math.ceil;" :: Number -> Number
2134

35+
-- | Returns the cosine of the argument.
2236
foreign import cos "var cos = Math.cos;" :: Radians -> Number
2337

38+
-- | Returns `e` exponentiated to the power of the argument.
2439
foreign import exp "var exp = Math.exp;" :: Number -> Number
2540

41+
-- | Returns the largest integer not larger than the argument.
2642
foreign import floor "var floor = Math.floor;" :: Number -> Number
2743

44+
-- | Returns the natural logarithm of a number.
2845
foreign import log "var log = Math.log;" :: Number -> Number
2946

47+
-- | Returns the largest of two numbers.
3048
foreign import max
3149
"function max(n1){\
3250
\ return function(n2) {\
3351
\ return Math.max(n1, n2);\
3452
\ }\
3553
\}" :: Number -> Number -> Number
3654

55+
-- | Returns the smallest of two numbers.
3756
foreign import min
3857
"function min(n1){\
3958
\ return function(n2) {\
4059
\ return Math.min(n1, n2);\
4160
\ }\
4261
\}" :: Number -> Number -> Number
4362

63+
-- | Return the first argument exponentiated to the power of the second argument.
4464
foreign import pow
4565
"function pow(n){\
4666
\ return function(p) {\
4767
\ return Math.pow(n, p);\
4868
\ }\
4969
\}" :: Number -> Number -> Number
5070

71+
-- | Returns the integer closest to the argument.
5172
foreign import round "var round = Math.round;" :: Number -> Number
5273

74+
-- | Returns the sine of the argument.
5375
foreign import sin "var sin = Math.sin;" :: Radians -> Number
5476

77+
-- | Returns the square root of the argument.
5578
foreign import sqrt "var sqrt = Math.sqrt;" :: Number -> Number
5679

80+
-- | Returns the tangent of the argument.
5781
foreign import tan "var tan = Math.tan;" :: Radians -> Number
5882

83+
-- | The base of natural logarithms, *e*, around 2.71828.
5984
foreign import e "var e = Math.E;" :: Number
85+
86+
-- | The natural logarithm of 2, around 0.6931.
6087
foreign import ln2 "var ln2 = Math.LN2;" :: Number
88+
89+
-- | The natural logarithm of 10, around 2.3025.
6190
foreign import ln10 "var ln10 = Math.LN10;" :: Number
91+
92+
-- | The base 2 logarithm of `e`, around 1.4426.
6293
foreign import log2e "var log2e = Math.LOG2E;" :: Number
94+
95+
-- | Base 10 logarithm of `e`, around 0.43429.
6396
foreign import log10e "var log10e = Math.LOG10E;" :: Number
97+
98+
-- | The ratio of the circumference of a circle to its diameter, around 3.14159.
6499
foreign import pi "var pi = Math.PI;" :: Number
100+
101+
-- | The Square root of one half, around 0.707107.
65102
foreign import sqrt1_2 "var sqrt1_2 = Math.SQRT1_2;" :: Number
103+
104+
-- | The square root of two, around 1.41421.
66105
foreign import sqrt2 "var sqrt2 = Math.SQRT2;" :: Number

0 commit comments

Comments
 (0)