From ef2ff146f918a67fd63094cf436557b0702dede0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Fri, 20 Mar 2015 14:40:43 +0100 Subject: [PATCH 1/4] add docs --- README.md | 218 +++++++++++++++++++++++++++++++++++++++++++------- src/Math.purs | 39 +++++++++ 2 files changed, 229 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 7721a1e..aa9af18 100644 --- a/README.md +++ b/README.md @@ -2,59 +2,221 @@ ## Module Math -### Types - type Radians = Number +Wraps the math functions and constants from Javascript's built-in `Math` object. +#### `Radians` -### Values +``` purescript +type Radians = Number +``` - abs :: Number -> Number +An alias to make types in this module more explicit. - acos :: Number -> Radians +#### `abs` - asin :: Number -> Radians +``` purescript +abs :: Number -> Number +``` - atan :: Number -> Radians +Returns the absolute value of the argument. - atan2 :: Number -> Number -> Radians +#### `acos` - ceil :: Number -> Number +``` purescript +acos :: Number -> Radians +``` - cos :: Radians -> Number +Returns the arccosine of the argument. - e :: Number +#### `asin` - exp :: Number -> Number +``` purescript +asin :: Number -> Radians +``` - floor :: Number -> Number +Returns the arcsine of the argument. - ln10 :: Number +#### `atan` - ln2 :: Number +``` purescript +atan :: Number -> Radians +``` - log :: Number -> Number +Returns the arctangent of the argument. - log10e :: Number +#### `atan2` - log2e :: Number +``` purescript +atan2 :: Number -> Number -> Radians +``` - max :: Number -> Number -> Number +Four-quadrant tangent inverse. Given `y` and `x`, returns the arctangent of +`y / x`, where the signs of both arguments are used to determine the sign +of the result. +If the first argument is negative, the result will be negative. +The result is the counterclockwise angle between the positive x axis and +the point `(x, y)`. - min :: Number -> Number -> Number +#### `ceil` - pi :: Number +``` purescript +ceil :: Number -> Number +``` - pow :: Number -> Number -> Number +Returns the smallest integer greater than or equal to the argument. - round :: Number -> Number +#### `cos` - sin :: Radians -> Number +``` purescript +cos :: Radians -> Number +``` - sqrt :: Number -> Number +Returns the cosine of the argument. + +#### `exp` + +``` purescript +exp :: Number -> Number +``` + +Returns `e` exponentiated to the power of the argument. + +#### `floor` + +``` purescript +floor :: Number -> Number +``` + +Returns the largest integer less than or equal to the argument. + +#### `log` + +``` purescript +log :: Number -> Number +``` + +Returns the natural logarithm of a number. + +#### `max` + +``` purescript +max :: Number -> Number -> Number +``` + +Returns the largest of two numbers. + +#### `min` + +``` purescript +min :: Number -> Number -> Number +``` + +Returns the smallest of two numbers. + +#### `pow` + +``` purescript +pow :: Number -> Number -> Number +``` + +Return the first argument exponentiated to the power of the second argument. + +#### `round` + +``` purescript +round :: Number -> Number +``` + +Returns the integer nearest to the argument. + +#### `sin` + +``` purescript +sin :: Radians -> Number +``` + +Returns the sine of the argument. + +#### `sqrt` + +``` purescript +sqrt :: Number -> Number +``` + +Returns the square root of the argument. + +#### `tan` + +``` purescript +tan :: Radians -> Number +``` + +Returns the tangent of the argument. + +#### `e` + +``` purescript +e :: Number +``` + +Euler's constant and the base of natural logarithms, approximately 2.718. + +#### `ln2` + +``` purescript +ln2 :: Number +``` + +Natural logarithm of 2, approximately 0.693. + +#### `ln10` + +``` purescript +ln10 :: Number +``` + +Natural logarithm of 10, approximately 2.303. + +#### `log2e` + +``` purescript +log2e :: Number +``` + +Base 2 logarithm of `e`, approximately 1.443. + +#### `log10e` + +``` purescript +log10e :: Number +``` + +Base 10 logarithm of `e`, approximately 0.434. + +#### `pi` + +``` purescript +pi :: Number +``` + +Ratio of the circumference of a circle to its diameter, approximately 3.14159. + +#### `sqrt1_2` + +``` purescript +sqrt1_2 :: Number +``` + +Square root of 1/2, approximately 0.707. + +#### `sqrt2` + +``` purescript +sqrt2 :: Number +``` + +Square root of 2, approximately 1.414. - sqrt1_2 :: Number - sqrt2 :: Number - tan :: Radians -> Number \ No newline at end of file diff --git a/src/Math.purs b/src/Math.purs index 009fa48..acebf9d 100644 --- a/src/Math.purs +++ b/src/Math.purs @@ -1,15 +1,27 @@ +-- | Wraps the math functions and constants from Javascript's built-in `Math` object. module Math where +-- | An alias to make types in this module more explicit. type Radians = Number +-- | Returns the absolute value of the argument. foreign import abs "var abs = Math.abs;" :: Number -> Number +-- | Returns the arccosine of the argument. foreign import acos "var acos = Math.acos;" :: Number -> Radians +-- | Returns the arcsine of the argument. foreign import asin "var asin = Math.asin;" :: Number -> Radians +-- | Returns the arctangent of the argument. foreign import atan "var atan = Math.atan;" :: Number -> Radians +-- | Four-quadrant tangent inverse. Given `y` and `x`, returns the arctangent of +-- | `y / x`, where the signs of both arguments are used to determine the sign +-- | of the result. +-- | If the first argument is negative, the result will be negative. +-- | The result is the counterclockwise angle between the positive x axis and +-- | the point `(x, y)`. foreign import atan2 "function atan2(y){\ \ return function (x) {\ @@ -17,16 +29,22 @@ foreign import atan2 \ };\ \}" :: Number -> Number -> Radians +-- | Returns the smallest integer greater than or equal to the argument. foreign import ceil "var ceil = Math.ceil;" :: Number -> Number +-- | Returns the cosine of the argument. foreign import cos "var cos = Math.cos;" :: Radians -> Number +-- | Returns `e` exponentiated to the power of the argument. foreign import exp "var exp = Math.exp;" :: Number -> Number +-- | Returns the largest integer less than or equal to the argument. foreign import floor "var floor = Math.floor;" :: Number -> Number +-- | Returns the natural logarithm of a number. foreign import log "var log = Math.log;" :: Number -> Number +-- | Returns the largest of two numbers. foreign import max "function max(n1){\ \ return function(n2) {\ @@ -34,6 +52,7 @@ foreign import max \ }\ \}" :: Number -> Number -> Number +-- | Returns the smallest of two numbers. foreign import min "function min(n1){\ \ return function(n2) {\ @@ -41,6 +60,7 @@ foreign import min \ }\ \}" :: Number -> Number -> Number +-- | Return the first argument exponentiated to the power of the second argument. foreign import pow "function pow(n){\ \ return function(p) {\ @@ -48,19 +68,38 @@ foreign import pow \ }\ \}" :: Number -> Number -> Number +-- | Returns the integer nearest to the argument. foreign import round "var round = Math.round;" :: Number -> Number +-- | Returns the sine of the argument. foreign import sin "var sin = Math.sin;" :: Radians -> Number +-- | Returns the square root of the argument. foreign import sqrt "var sqrt = Math.sqrt;" :: Number -> Number +-- | Returns the tangent of the argument. foreign import tan "var tan = Math.tan;" :: Radians -> Number +-- | Euler's constant and the base of natural logarithms, approximately 2.718. foreign import e "var e = Math.E;" :: Number + +-- | Natural logarithm of 2, approximately 0.693. foreign import ln2 "var ln2 = Math.LN2;" :: Number + +-- | Natural logarithm of 10, approximately 2.303. foreign import ln10 "var ln10 = Math.LN10;" :: Number + +-- | Base 2 logarithm of `e`, approximately 1.443. foreign import log2e "var log2e = Math.LOG2E;" :: Number + +-- | Base 10 logarithm of `e`, approximately 0.434. foreign import log10e "var log10e = Math.LOG10E;" :: Number + +-- | Ratio of the circumference of a circle to its diameter, approximately 3.14159. foreign import pi "var pi = Math.PI;" :: Number + +-- | Square root of 1/2, approximately 0.707. foreign import sqrt1_2 "var sqrt1_2 = Math.SQRT1_2;" :: Number + +-- | Square root of 2, approximately 1.414. foreign import sqrt2 "var sqrt2 = Math.SQRT2;" :: Number From e62099f407f6ef302124cdf7fd0e5ca7a98934f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Fri, 20 Mar 2015 15:14:05 +0100 Subject: [PATCH 2/4] add MDN link --- README.md | 1 + src/Math.purs | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index aa9af18..895fdb6 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Wraps the math functions and constants from Javascript's built-in `Math` object. +See [Math Documentation at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). #### `Radians` diff --git a/src/Math.purs b/src/Math.purs index acebf9d..d948025 100644 --- a/src/Math.purs +++ b/src/Math.purs @@ -1,4 +1,5 @@ -- | Wraps the math functions and constants from Javascript's built-in `Math` object. +-- | See [Math Documentation at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). module Math where -- | An alias to make types in this module more explicit. From e0dd5eca81099195cd550706f4b4d09e71df651a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Fri, 20 Mar 2015 15:18:23 +0100 Subject: [PATCH 3/4] fix MDN link --- README.md | 2 +- src/Math.purs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 895fdb6..e736980 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Wraps the math functions and constants from Javascript's built-in `Math` object. -See [Math Documentation at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). +See [Math Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). #### `Radians` diff --git a/src/Math.purs b/src/Math.purs index d948025..9664ebe 100644 --- a/src/Math.purs +++ b/src/Math.purs @@ -1,5 +1,5 @@ -- | Wraps the math functions and constants from Javascript's built-in `Math` object. --- | See [Math Documentation at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). +-- | See [Math Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). module Math where -- | An alias to make types in this module more explicit. From 69b4a4fe82578be701cd7aa834795100386cdd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Sat, 21 Mar 2015 22:57:29 +0100 Subject: [PATCH 4/4] cleanup --- README.md | 37 ++++++++++++++++++------------------- src/Math.purs | 37 ++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index e736980..8e33588 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Returns the absolute value of the argument. acos :: Number -> Radians ``` -Returns the arccosine of the argument. +Returns the inverse cosine of the argument. #### `asin` @@ -36,7 +36,7 @@ Returns the arccosine of the argument. asin :: Number -> Radians ``` -Returns the arcsine of the argument. +Returns the inverse sine of the argument. #### `atan` @@ -44,7 +44,7 @@ Returns the arcsine of the argument. atan :: Number -> Radians ``` -Returns the arctangent of the argument. +Returns the inverse tangent of the argument. #### `atan2` @@ -52,12 +52,11 @@ Returns the arctangent of the argument. atan2 :: Number -> Number -> Radians ``` -Four-quadrant tangent inverse. Given `y` and `x`, returns the arctangent of -`y / x`, where the signs of both arguments are used to determine the sign -of the result. +Four-quadrant tangent inverse. Given the arguments `y` and `x`, returns +the inverse tangent of `y / x`, where the signs of both arguments are used +to determine the sign of the result. If the first argument is negative, the result will be negative. -The result is the counterclockwise angle between the positive x axis and -the point `(x, y)`. +The result is the angle between the positive x axis and a point `(x, y)`. #### `ceil` @@ -65,7 +64,7 @@ the point `(x, y)`. ceil :: Number -> Number ``` -Returns the smallest integer greater than or equal to the argument. +Returns the smallest integer not smaller than the argument. #### `cos` @@ -89,7 +88,7 @@ Returns `e` exponentiated to the power of the argument. floor :: Number -> Number ``` -Returns the largest integer less than or equal to the argument. +Returns the largest integer not larger than the argument. #### `log` @@ -129,7 +128,7 @@ Return the first argument exponentiated to the power of the second argument. round :: Number -> Number ``` -Returns the integer nearest to the argument. +Returns the integer closest to the argument. #### `sin` @@ -161,7 +160,7 @@ Returns the tangent of the argument. e :: Number ``` -Euler's constant and the base of natural logarithms, approximately 2.718. +The base of natural logarithms, *e*, around 2.71828. #### `ln2` @@ -169,7 +168,7 @@ Euler's constant and the base of natural logarithms, approximately 2.718. ln2 :: Number ``` -Natural logarithm of 2, approximately 0.693. +The natural logarithm of 2, around 0.6931. #### `ln10` @@ -177,7 +176,7 @@ Natural logarithm of 2, approximately 0.693. ln10 :: Number ``` -Natural logarithm of 10, approximately 2.303. +The natural logarithm of 10, around 2.3025. #### `log2e` @@ -185,7 +184,7 @@ Natural logarithm of 10, approximately 2.303. log2e :: Number ``` -Base 2 logarithm of `e`, approximately 1.443. +The base 2 logarithm of `e`, around 1.4426. #### `log10e` @@ -193,7 +192,7 @@ Base 2 logarithm of `e`, approximately 1.443. log10e :: Number ``` -Base 10 logarithm of `e`, approximately 0.434. +Base 10 logarithm of `e`, around 0.43429. #### `pi` @@ -201,7 +200,7 @@ Base 10 logarithm of `e`, approximately 0.434. pi :: Number ``` -Ratio of the circumference of a circle to its diameter, approximately 3.14159. +The ratio of the circumference of a circle to its diameter, around 3.14159. #### `sqrt1_2` @@ -209,7 +208,7 @@ Ratio of the circumference of a circle to its diameter, approximately 3.14159. sqrt1_2 :: Number ``` -Square root of 1/2, approximately 0.707. +The Square root of one half, around 0.707107. #### `sqrt2` @@ -217,7 +216,7 @@ Square root of 1/2, approximately 0.707. sqrt2 :: Number ``` -Square root of 2, approximately 1.414. +The square root of two, around 1.41421. diff --git a/src/Math.purs b/src/Math.purs index 9664ebe..06c0f01 100644 --- a/src/Math.purs +++ b/src/Math.purs @@ -8,21 +8,20 @@ type Radians = Number -- | Returns the absolute value of the argument. foreign import abs "var abs = Math.abs;" :: Number -> Number --- | Returns the arccosine of the argument. +-- | Returns the inverse cosine of the argument. foreign import acos "var acos = Math.acos;" :: Number -> Radians --- | Returns the arcsine of the argument. +-- | Returns the inverse sine of the argument. foreign import asin "var asin = Math.asin;" :: Number -> Radians --- | Returns the arctangent of the argument. +-- | Returns the inverse tangent of the argument. foreign import atan "var atan = Math.atan;" :: Number -> Radians --- | Four-quadrant tangent inverse. Given `y` and `x`, returns the arctangent of --- | `y / x`, where the signs of both arguments are used to determine the sign --- | of the result. +-- | Four-quadrant tangent inverse. Given the arguments `y` and `x`, returns +-- | the inverse tangent of `y / x`, where the signs of both arguments are used +-- | to determine the sign of the result. -- | If the first argument is negative, the result will be negative. --- | The result is the counterclockwise angle between the positive x axis and --- | the point `(x, y)`. +-- | The result is the angle between the positive x axis and a point `(x, y)`. foreign import atan2 "function atan2(y){\ \ return function (x) {\ @@ -30,7 +29,7 @@ foreign import atan2 \ };\ \}" :: Number -> Number -> Radians --- | Returns the smallest integer greater than or equal to the argument. +-- | Returns the smallest integer not smaller than the argument. foreign import ceil "var ceil = Math.ceil;" :: Number -> Number -- | Returns the cosine of the argument. @@ -39,7 +38,7 @@ foreign import cos "var cos = Math.cos;" :: Radians -> Number -- | Returns `e` exponentiated to the power of the argument. foreign import exp "var exp = Math.exp;" :: Number -> Number --- | Returns the largest integer less than or equal to the argument. +-- | Returns the largest integer not larger than the argument. foreign import floor "var floor = Math.floor;" :: Number -> Number -- | Returns the natural logarithm of a number. @@ -69,7 +68,7 @@ foreign import pow \ }\ \}" :: Number -> Number -> Number --- | Returns the integer nearest to the argument. +-- | Returns the integer closest to the argument. foreign import round "var round = Math.round;" :: Number -> Number -- | Returns the sine of the argument. @@ -81,26 +80,26 @@ foreign import sqrt "var sqrt = Math.sqrt;" :: Number -> Number -- | Returns the tangent of the argument. foreign import tan "var tan = Math.tan;" :: Radians -> Number --- | Euler's constant and the base of natural logarithms, approximately 2.718. +-- | The base of natural logarithms, *e*, around 2.71828. foreign import e "var e = Math.E;" :: Number --- | Natural logarithm of 2, approximately 0.693. +-- | The natural logarithm of 2, around 0.6931. foreign import ln2 "var ln2 = Math.LN2;" :: Number --- | Natural logarithm of 10, approximately 2.303. +-- | The natural logarithm of 10, around 2.3025. foreign import ln10 "var ln10 = Math.LN10;" :: Number --- | Base 2 logarithm of `e`, approximately 1.443. +-- | The base 2 logarithm of `e`, around 1.4426. foreign import log2e "var log2e = Math.LOG2E;" :: Number --- | Base 10 logarithm of `e`, approximately 0.434. +-- | Base 10 logarithm of `e`, around 0.43429. foreign import log10e "var log10e = Math.LOG10E;" :: Number --- | Ratio of the circumference of a circle to its diameter, approximately 3.14159. +-- | The ratio of the circumference of a circle to its diameter, around 3.14159. foreign import pi "var pi = Math.PI;" :: Number --- | Square root of 1/2, approximately 0.707. +-- | The Square root of one half, around 0.707107. foreign import sqrt1_2 "var sqrt1_2 = Math.SQRT1_2;" :: Number --- | Square root of 2, approximately 1.414. +-- | The square root of two, around 1.41421. foreign import sqrt2 "var sqrt2 = Math.SQRT2;" :: Number