From d94f3a70ea23934e0e04e47b96669d6864d88e70 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 03:30:16 -0300 Subject: [PATCH 1/7] initial Int docstring --- src/Core__Int.mjs | 7 +- src/Core__Int.resi | 273 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 src/Core__Int.resi diff --git a/src/Core__Int.mjs b/src/Core__Int.mjs index bc8c4402..98b0dc45 100644 --- a/src/Core__Int.mjs +++ b/src/Core__Int.mjs @@ -1,8 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -var Constants = {}; - function fromString(radix, x) { var maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x); if (isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) { @@ -12,6 +10,11 @@ function fromString(radix, x) { } } +var Constants = { + minValue: -2147483648, + maxValue: 2147483647 +}; + export { Constants , fromString , diff --git a/src/Core__Int.resi b/src/Core__Int.resi new file mode 100644 index 00000000..ed523446 --- /dev/null +++ b/src/Core__Int.resi @@ -0,0 +1,273 @@ +/* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/*** +Functions for interacting with JavaScript Number. +See: [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number). +*/ + +module Constants: { + /** + The smallest positive number represented in JavaScript. + See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) + on MDN. + + ## Examples + + ```rescript + Console.log(Int.Constants.minValue) + ``` + */ + @inline + let minValue: int + /** + The largest positive number represented in JavaScript. + See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) + on MDN. + + ## Examples + + ```rescript + Console.log(Int.Constants.maxValue) + ``` + */ + @inline + let maxValue: int +} + +/** +`toExponential(n)` return a `string` representing the given value in exponential +notation. +See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) +on MDN. + +## Examples + +```rescript +Int.toExponential(1000) // "1e+3" +Int.toExponential(-1000) // "-1e+3" +``` +*/ +@send +external toExponential: int => string = "toExponential" + +/** +`toExponential(n, ~digits)` return a `string` representing the given value in +exponential notation. `digits` specifies how many digits should appear after +the decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) +on MDN. + +## Examples + +```rescript +Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" +Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" +``` +## Expections + +`RangeError`: + +- If `digits` less than 0 or greater than 10. +*/ +@send +external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" + +/** +`toFixed(n)` return a `string` representing the given value using fixed-point +notation. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) +on MDN. + + +## Examples + +```rescript +Int.toFixed(123456) // "123456.00" +Int.toFixed(10) // "10.00" +``` +*/ +@send +external toFixed: int => string = "toFixed" + +/** +`toFixedWithPrecision(n, ~digits)` return a `string` representing the given +value using fixed-point notation. `digits` specifies how many digits should +appear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) +on MDN. + +## Examples + +```rescript +Int.toFixed(300, ~digits=4) // "300.0000" +Int.toFixed(300, ~digits=1) // "300.0" +``` + +## Expections + +`RangeError`: + +- If `digits` is less than 0 or larger than 100. +*/ +@send +external toFixedWithPrecision: (int, ~digits: int) => string = "toFixed" + +/** +`toPrecision(n)` return a `string` representing the giver value with precision. +This function omits the argument that controls precision, so it behaves like +`toString`. See `toPrecisionWithPrecision` to control precision. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN. + +## Examples + +```rescript +Int.toPrecision(100) // "100" +Int.toPrecision(1) // "1" +``` +*/ +@send +external toPrecision: int => string = "toPrecision" + +/** +`toPrecision(n, ~digits)` return a `string` representing the giver value with +precision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN. + +## Examples + +```rescript +Int.toPrecision(100, ~digits=2) // "1.0e+2" +Int.toPrecision(1) // "1.0" +``` + +## Expections + +`RangeError`: + +- If `~digits` is not between 1 and 100 (inclusive). Implementations are allowed +to support larger and smaller values as well. ECMA-262 only requires a precision +of up to 21 significant digits. + +*/ +@send +external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" + +/** +`toString(n)` return a `string` representing the given value. +See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) +on MDN. + +## Examples + +```rescript +Int.toString(1000) // "1000" +Int.toString(-1000) // "-1000" +``` +*/ +@send +external toString: int => string = "toString" + +/** +`toStringWithRadix(n, ~radix)` return a `string` representing the given value. +`~radix` specifies the radix base to use for the formatted number. +See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) +on MDN. + +## Examples + +```rescript +Int.toString(6, ~radix=2) // "110" +Int.toString(3735928559, ~radix=16) // "deadbeef" +Int.toStringWithRadix(123456, ~radix=36) // "2n9c" +``` + +## Exceptions + +`RangeError`: + +- if `~radix` is less than 2 or greater than 36. +*/ +@send +external toStringWithRadix: (int, ~radix: int) => string = "toString" + +/** +`toLocaleString(n)` return a `string` with language-sensitive representing the +given value. See [`Number.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) on MDN. + +## Examples + +```rescript +// If the application uses English as the default language +Int.toLocaleString(1000) // "1,000" + +// If the application uses Portuguese Brazil as the default language +Int.toLocaleString(1000) // "1.000" +``` +*/ +@send +external toLocaleString: int => string = "toLocaleString" + +/** +`toFloat(n)` return a `float` representing the given value. + +## Examples + +```rescript +Int.toFloat(100) == 100. +Int.toFloat(2) == 2.0 +``` +*/ +external toFloat: int => float = "%identity" + +/** +`fromFloat(n)` return an `int` representing the given value. + +## Examples + +```rescript +Int.fromFloat(2.0) == 2 +Int.fromFloat(1.0) == 1 +``` +*/ +external fromFloat: float => int = "%intoffloat" + +/** +`fromString(~radix?, v)` return an `option` representing the given value +`v`. `~radix` specifies the radix base to use for the formatted number. + +## Examples + +```rescript +Int.fromString("0") == Some(0) +Int.fromString("NaN") == None +``` +*/ +let fromString: (~radix: int=?, 'a) => option + +/** +`mod(n1, n2)` calculates the modulo (remainder after division) of two integers. + +## Examples + +```rescript +Int.mod(7, 4) == 3 +``` +*/ +external mod: (int, int) => int = "%modint" From 5aa03b1f876974ee8d64cdbde912750095496ef5 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 04:45:35 -0300 Subject: [PATCH 2/7] fix typo --- src/Core__Int.resi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Core__Int.resi b/src/Core__Int.resi index ed523446..cfc3d442 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -84,7 +84,8 @@ on MDN. Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" ``` -## Expections + +## Exceptions `RangeError`: @@ -157,7 +158,7 @@ Int.toPrecision(100, ~digits=2) // "1.0e+2" Int.toPrecision(1) // "1.0" ``` -## Expections +## Exceptions `RangeError`: From 641856a2310d1d0237e025d0359cbad323f83309 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 16:32:34 -0300 Subject: [PATCH 3/7] Update src/Core__Int.resi Co-authored-by: Gabriel Nordeborn --- src/Core__Int.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core__Int.resi b/src/Core__Int.resi index cfc3d442..ebdd4973 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -231,7 +231,7 @@ external toLocaleString: int => string = "toLocaleString" ## Examples ```rescript -Int.toFloat(100) == 100. +Int.toFloat(100) == 100.0 Int.toFloat(2) == 2.0 ``` */ From a7b0ad9fb7cbb59751a1c79ddafc67807ed83c05 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 16:32:43 -0300 Subject: [PATCH 4/7] Update src/Core__Int.resi Co-authored-by: Gabriel Nordeborn --- src/Core__Int.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core__Int.resi b/src/Core__Int.resi index ebdd4973..ee0abaf7 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -123,7 +123,7 @@ Int.toFixed(300, ~digits=4) // "300.0000" Int.toFixed(300, ~digits=1) // "300.0" ``` -## Expections +## Exceptions `RangeError`: From 553647399c576a19a7cc81d7ff550f8e154e6f41 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 16:34:47 -0300 Subject: [PATCH 5/7] Update src/Core__Int.resi Co-authored-by: Gabriel Nordeborn --- src/Core__Int.resi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Core__Int.resi b/src/Core__Int.resi index ee0abaf7..d8f6f4aa 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -87,9 +87,7 @@ Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" ## Exceptions -`RangeError`: - -- If `digits` less than 0 or greater than 10. +- `RangeError`: If `digits` less than 0 or greater than 10. */ @send external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" From d007e94d47253ec66da4d3cb8501910398abb3d7 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 16:57:21 -0300 Subject: [PATCH 6/7] update --- src/Core__Int.resi | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Core__Int.resi b/src/Core__Int.resi index d8f6f4aa..5793df64 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -236,29 +236,33 @@ Int.toFloat(2) == 2.0 external toFloat: int => float = "%identity" /** -`fromFloat(n)` return an `int` representing the given value. +`fromFloat(n)` return an `int` representing the given value. The conversion is +done by truncating the decimal part. ## Examples ```rescript Int.fromFloat(2.0) == 2 -Int.fromFloat(1.0) == 1 +Int.fromFloat(1.999) == 1 +Int.fromFloat(1.5) == 1 +Int.fromFloat(0.9999) == 0 ``` */ external fromFloat: float => int = "%intoffloat" /** -`fromString(~radix?, v)` return an `option` representing the given value -`v`. `~radix` specifies the radix base to use for the formatted number. +`fromString(~radix?, str)` return an `option` representing the given value +`str`. `~radix` specifies the radix base to use for the formatted number. ## Examples ```rescript Int.fromString("0") == Some(0) Int.fromString("NaN") == None +Int.fromString(~radix=2, "6") == None ``` */ -let fromString: (~radix: int=?, 'a) => option +let fromString: (~radix: int=?, string) => option /** `mod(n1, n2)` calculates the modulo (remainder after division) of two integers. From 4c72586e76574d4ae3d288f2cf98d225c282f89d Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 16 Feb 2023 17:03:19 -0300 Subject: [PATCH 7/7] fix exceptions --- src/Core__Int.resi | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Core__Int.resi b/src/Core__Int.resi index 5793df64..68498f18 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -123,9 +123,7 @@ Int.toFixed(300, ~digits=1) // "300.0" ## Exceptions -`RangeError`: - -- If `digits` is less than 0 or larger than 100. +- `RangeError`: If `digits` is less than 0 or larger than 100. */ @send external toFixedWithPrecision: (int, ~digits: int) => string = "toFixed" @@ -158,11 +156,9 @@ Int.toPrecision(1) // "1.0" ## Exceptions -`RangeError`: - -- If `~digits` is not between 1 and 100 (inclusive). Implementations are allowed -to support larger and smaller values as well. ECMA-262 only requires a precision -of up to 21 significant digits. +- `RangeError`: If `digits` is not between 1 and 100 (inclusive). +Implementations are allowed to support larger and smaller values as well. +ECMA-262 only requires a precision of up to 21 significant digits. */ @send @@ -199,9 +195,7 @@ Int.toStringWithRadix(123456, ~radix=36) // "2n9c" ## Exceptions -`RangeError`: - -- if `~radix` is less than 2 or greater than 36. +`RangeError`: if `radix` is less than 2 or greater than 36. */ @send external toStringWithRadix: (int, ~radix: int) => string = "toString"