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

Commit c0ec29e

Browse files
committed
Updates for 0.7
1 parent fc36562 commit c0ec29e

File tree

2 files changed

+97
-53
lines changed

2 files changed

+97
-53
lines changed

src/Math.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Math
5+
6+
exports.abs = Math.abs;
7+
8+
exports.acos = Math.acos;
9+
10+
exports.asin = Math.asin;
11+
12+
exports.atan = Math.atan;
13+
14+
exports.atan2 = function(y){
15+
return function (x) {
16+
return Math.atan2(y, x);
17+
};
18+
};
19+
20+
exports.ceil = Math.ceil;
21+
22+
exports.cos = Math.cos;
23+
24+
exports.exp = Math.exp;
25+
26+
exports.floor = Math.floor;
27+
28+
exports.log = Math.log;
29+
30+
exports.max = function(n1){
31+
return function(n2) {
32+
return Math.max(n1, n2);
33+
};
34+
};
35+
36+
exports.min = function(n1){
37+
return function(n2) {
38+
return Math.min(n1, n2);
39+
};
40+
};
41+
42+
exports.pow = function(n){
43+
return function(p) {
44+
return Math.pow(n, p);
45+
};
46+
};
47+
48+
exports.round = Math.round;
49+
50+
exports.sin = Math.sin;
51+
52+
exports.sqrt = Math.sqrt;
53+
54+
exports.tan = Math.tan;
55+
56+
exports.e = Math.E;
57+
58+
exports.ln2 = Math.LN2;
59+
60+
exports.ln10 = Math.LN10;
61+
62+
exports.log2e = Math.LOG2E;
63+
64+
exports.log10e = Math.LOG10E;
65+
66+
exports.pi = Math.PI;
67+
68+
exports.sqrt1_2 = Math.SQRT1_2;
69+
70+
exports.sqrt2 = Math.SQRT2;

src/Math.purs

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,86 @@
22
-- | See [Math Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math).
33
module Math where
44

5+
import Prelude
6+
57
-- | An alias to make types in this module more explicit.
68
type Radians = Number
79

810
-- | Returns the absolute value of the argument.
9-
foreign import abs "var abs = Math.abs;" :: Number -> Number
11+
foreign import abs :: Number -> Number
1012

1113
-- | Returns the inverse cosine of the argument.
12-
foreign import acos "var acos = Math.acos;" :: Number -> Radians
14+
foreign import acos :: Number -> Radians
1315

1416
-- | Returns the inverse sine of the argument.
15-
foreign import asin "var asin = Math.asin;" :: Number -> Radians
17+
foreign import asin :: Number -> Radians
1618

1719
-- | Returns the inverse tangent of the argument.
18-
foreign import atan "var atan = Math.atan;" :: Number -> Radians
20+
foreign import atan :: Number -> Radians
1921

2022
-- | Four-quadrant tangent inverse. Given the arguments `y` and `x`, returns
2123
-- | the inverse tangent of `y / x`, where the signs of both arguments are used
2224
-- | to determine the sign of the result.
2325
-- | If the first argument is negative, the result will be negative.
2426
-- | The result is the angle between the positive x axis and a point `(x, y)`.
25-
foreign import atan2
26-
"""
27-
function atan2(y){
28-
return function (x) {
29-
return Math.atan2(y, x);
30-
};
31-
}
32-
""" :: Number -> Number -> Radians
27+
foreign import atan2 :: Number -> Number -> Radians
3328

3429
-- | Returns the smallest integer not smaller than the argument.
35-
foreign import ceil "var ceil = Math.ceil;" :: Number -> Number
30+
foreign import ceil :: Number -> Number
3631

3732
-- | Returns the cosine of the argument.
38-
foreign import cos "var cos = Math.cos;" :: Radians -> Number
33+
foreign import cos :: Radians -> Number
3934

4035
-- | Returns `e` exponentiated to the power of the argument.
41-
foreign import exp "var exp = Math.exp;" :: Number -> Number
36+
foreign import exp :: Number -> Number
4237

4338
-- | Returns the largest integer not larger than the argument.
44-
foreign import floor "var floor = Math.floor;" :: Number -> Number
39+
foreign import floor :: Number -> Number
4540

4641
-- | Returns the natural logarithm of a number.
47-
foreign import log "var log = Math.log;" :: Number -> Number
42+
foreign import log :: Number -> Number
4843

4944
-- | Returns the largest of two numbers.
50-
foreign import max
51-
"""
52-
function max(n1){
53-
return function(n2) {
54-
return Math.max(n1, n2);
55-
};
56-
}
57-
""" :: Number -> Number -> Number
45+
foreign import max :: Number -> Number -> Number
5846

5947
-- | Returns the smallest of two numbers.
60-
foreign import min
61-
"""
62-
function min(n1){
63-
return function(n2) {
64-
return Math.min(n1, n2);
65-
};
66-
}
67-
""" :: Number -> Number -> Number
48+
foreign import min :: Number -> Number -> Number
6849

6950
-- | Return the first argument exponentiated to the power of the second argument.
70-
foreign import pow
71-
"""
72-
function pow(n){
73-
return function(p) {
74-
return Math.pow(n, p);
75-
};
76-
}
77-
""" :: Number -> Number -> Number
51+
foreign import pow :: Number -> Number -> Number
7852

7953
-- | Returns the integer closest to the argument.
80-
foreign import round "var round = Math.round;" :: Number -> Number
54+
foreign import round :: Number -> Number
8155

8256
-- | Returns the sine of the argument.
83-
foreign import sin "var sin = Math.sin;" :: Radians -> Number
57+
foreign import sin :: Radians -> Number
8458

8559
-- | Returns the square root of the argument.
86-
foreign import sqrt "var sqrt = Math.sqrt;" :: Number -> Number
60+
foreign import sqrt :: Number -> Number
8761

8862
-- | Returns the tangent of the argument.
89-
foreign import tan "var tan = Math.tan;" :: Radians -> Number
63+
foreign import tan :: Radians -> Number
9064

9165
-- | The base of natural logarithms, *e*, around 2.71828.
92-
foreign import e "var e = Math.E;" :: Number
66+
foreign import e :: Number
9367

9468
-- | The natural logarithm of 2, around 0.6931.
95-
foreign import ln2 "var ln2 = Math.LN2;" :: Number
69+
foreign import ln2 :: Number
9670

9771
-- | The natural logarithm of 10, around 2.3025.
98-
foreign import ln10 "var ln10 = Math.LN10;" :: Number
72+
foreign import ln10 :: Number
9973

10074
-- | The base 2 logarithm of `e`, around 1.4426.
101-
foreign import log2e "var log2e = Math.LOG2E;" :: Number
75+
foreign import log2e :: Number
10276

10377
-- | Base 10 logarithm of `e`, around 0.43429.
104-
foreign import log10e "var log10e = Math.LOG10E;" :: Number
78+
foreign import log10e :: Number
10579

10680
-- | The ratio of the circumference of a circle to its diameter, around 3.14159.
107-
foreign import pi "var pi = Math.PI;" :: Number
81+
foreign import pi :: Number
10882

10983
-- | The Square root of one half, around 0.707107.
110-
foreign import sqrt1_2 "var sqrt1_2 = Math.SQRT1_2;" :: Number
84+
foreign import sqrt1_2 :: Number
11185

11286
-- | The square root of two, around 1.41421.
113-
foreign import sqrt2 "var sqrt2 = Math.SQRT2;" :: Number
87+
foreign import sqrt2 :: Number

0 commit comments

Comments
 (0)