-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use native bigint type * Changelog * Update to native built-in methods * Update test output * Fix a doctest * Fix dict error in docs test by upgrading even more * Fix changelog
- Loading branch information
1 parent
4394682
commit 5d675f7
Showing
24 changed files
with
133 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,95 @@ | ||
type t = Js.Types.bigint_val | ||
@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN" | ||
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN" | ||
|
||
@val external asIntN: (~width: int, t) => t = "BigInt.asIntN" | ||
@val external asUintN: (~width: int, t) => t = "BigInt.asUintN" | ||
@val external fromString: string => bigint = "BigInt" | ||
|
||
@val external fromString: string => t = "BigInt" | ||
@val external fromInt: int => t = "BigInt" | ||
@val external fromFloat: float => t = "BigInt" | ||
@val | ||
/** | ||
Parses the given `string` into a `bigint` using JavaScript semantics. Return the | ||
number as a `bigint` if successfully parsed. Uncaught syntax exception otherwise. | ||
@send external toString: t => string = "toString" | ||
@send external toStringWithRadix: (t, ~radix: int) => string = "toString" | ||
@send external toLocaleString: t => string = "toLocaleString" | ||
## Examples | ||
@val external toFloat: t => float = "Number" | ||
```rescript | ||
/* returns 123n */ | ||
BigInt.fromStringExn("123") | ||
/* returns 0n */ | ||
BigInt.fromStringExn("") | ||
/* returns 17n */ | ||
BigInt.fromStringExn("0x11") | ||
/* returns 3n */ | ||
BigInt.fromStringExn("0b11") | ||
/* returns 9n */ | ||
BigInt.fromStringExn("0o11") | ||
/* catch exception */ | ||
try { | ||
BigInt.fromStringExn("a") | ||
} catch { | ||
| Exn.Error(_error) => 0n | ||
} | ||
``` | ||
*/ | ||
external fromStringExn: string => bigint = "BigInt" | ||
@val external fromInt: int => bigint = "BigInt" | ||
@val external fromFloat: float => bigint = "BigInt" | ||
|
||
@send | ||
/** | ||
Formats a `bigint` as a string. Return a `string` representing the given value. | ||
See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN. | ||
## Examples | ||
```rescript | ||
/* prints "123" */ | ||
Js.BigInt.toString(123n)->Js.log | ||
``` | ||
*/ | ||
external toString: bigint => string = "toString" | ||
@send external toStringWithRadix: (bigint, ~radix: int) => string = "toString" | ||
|
||
@send | ||
/** | ||
Returns a string with a language-sensitive representation of this BigInt value. | ||
## Examples | ||
```rescript | ||
/* prints "123" */ | ||
Js.BigInt.toString(123n)->Js.log | ||
``` | ||
*/ | ||
external toLocaleString: bigint => string = "toLocaleString" | ||
|
||
@val external toFloat: bigint => float = "Number" | ||
|
||
let toInt = t => t->toFloat->Core__Int.fromFloat | ||
|
||
external \"+": (t, t) => t = "%addfloat" | ||
external \"-": (t, t) => t = "%subfloat" | ||
external \"*": (t, t) => t = "%mulfloat" | ||
external \"/": (t, t) => t = "%divfloat" | ||
external \"+": (bigint, bigint) => bigint = "%addbigint" | ||
external \"-": (bigint, bigint) => bigint = "%subbigint" | ||
external \"*": (bigint, bigint) => bigint = "%mulbigint" | ||
external \"/": (bigint, bigint) => bigint = "%divbigint" | ||
external \"~-": bigint => bigint = "%negbigint" | ||
external \"~+": bigint => bigint = "%identity" | ||
external \"**": (bigint, bigint) => bigint = "%powbigint" | ||
|
||
external add: (t, t) => t = "%addfloat" | ||
external sub: (t, t) => t = "%subfloat" | ||
external mul: (t, t) => t = "%mulfloat" | ||
external div: (t, t) => t = "%divfloat" | ||
external add: (bigint, bigint) => bigint = "%addfloat" | ||
external sub: (bigint, bigint) => bigint = "%subfloat" | ||
external mul: (bigint, bigint) => bigint = "%mulfloat" | ||
external div: (bigint, bigint) => bigint = "%divfloat" | ||
|
||
@noalloc external mod: (t, t) => t = "?fmod_float" | ||
external mod: (bigint, bigint) => bigint = "%modbigint" | ||
|
||
external land: (t, t) => t = "%andint" | ||
external lor: (t, t) => t = "%orint" | ||
external lxor: (t, t) => t = "%xorint" | ||
external land: (bigint, bigint) => bigint = "%andbigint" | ||
external lor: (bigint, bigint) => bigint = "%orbigint" | ||
external lxor: (bigint, bigint) => bigint = "%xorbigint" | ||
|
||
external lsl: (t, t) => t = "%lslint" | ||
external asr: (t, t) => t = "%asrint" | ||
external lsl: (bigint, bigint) => bigint = "%lslbigint" | ||
external asr: (bigint, bigint) => bigint = "%asrbigint" | ||
|
||
let exp = (x: t, y: t) => { | ||
let _ = x | ||
let _ = y | ||
%raw(`x ** y`) | ||
} | ||
let lnot = x => lxor(x, -1n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.