Skip to content

Docstrings for BigInt #7592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/artifacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,9 @@ lib/ocaml/Stdlib_AsyncIterator.resi
lib/ocaml/Stdlib_BigInt.cmi
lib/ocaml/Stdlib_BigInt.cmj
lib/ocaml/Stdlib_BigInt.cmt
lib/ocaml/Stdlib_BigInt.cmti
lib/ocaml/Stdlib_BigInt.res
lib/ocaml/Stdlib_BigInt.resi
lib/ocaml/Stdlib_BigInt64Array.cmi
lib/ocaml/Stdlib_BigInt64Array.cmj
lib/ocaml/Stdlib_BigInt64Array.cmt
Expand Down
92 changes: 0 additions & 92 deletions runtime/Stdlib_BigInt.res
Original file line number Diff line number Diff line change
@@ -1,58 +1,11 @@
/**
Type representing a bigint.
*/
type t = bigint

@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN"
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN"

/**
Parses the given `string` into a `bigint` using JavaScript semantics. Return the
number as a `bigint` if successfully parsed. Throws a syntax exception otherwise.

## Examples

```rescript
BigInt.fromStringOrThrow("123")->assertEqual(123n)

BigInt.fromStringOrThrow("")->assertEqual(0n)

BigInt.fromStringOrThrow("0x11")->assertEqual(17n)

BigInt.fromStringOrThrow("0b11")->assertEqual(3n)

BigInt.fromStringOrThrow("0o11")->assertEqual(9n)

/* catch exception */
switch BigInt.fromStringOrThrow("a") {
| exception JsExn(_error) => assert(true)
| _bigInt => assert(false)
}
```
*/
@val
external fromStringOrThrow: string => bigint = "BigInt"

/**
Parses the given `string` into a `bigint` using JavaScript semantics. Returns
`Some(bigint)` if the string can be parsed, `None` otherwise.

## Examples

```rescript
BigInt.fromString("123")->assertEqual(Some(123n))

BigInt.fromString("")->assertEqual(Some(0n))

BigInt.fromString("0x11")->assertEqual(Some(17n))

BigInt.fromString("0b11")->assertEqual(Some(3n))

BigInt.fromString("0o11")->assertEqual(Some(9n))

BigInt.fromString("invalid")->assertEqual(None)
```
*/
let fromString = (value: string) => {
try Some(fromStringOrThrow(value)) catch {
| _ => None
Expand All @@ -64,26 +17,6 @@ external fromStringExn: string => bigint = "BigInt"

@val external fromInt: int => bigint = "BigInt"

/**
Converts a `float` to a `bigint` using JavaScript semantics.
Throws an exception if the float is not an integer or is infinite/NaN.

## Examples

```rescript
BigInt.fromFloatOrThrow(123.0)->assertEqual(123n)

BigInt.fromFloatOrThrow(0.0)->assertEqual(0n)

BigInt.fromFloatOrThrow(-456.0)->assertEqual(-456n)

/* This will throw an exception */
switch BigInt.fromFloatOrThrow(123.5) {
| exception JsExn(_error) => assert(true)
| _bigInt => assert(false)
}
```
*/
@val
external fromFloatOrThrow: float => bigint = "BigInt"

Expand All @@ -93,31 +26,12 @@ let fromFloat = (value: float) => {
}
}

/**
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
BigInt.toString(123n)->assertEqual("123")
```
*/
@send
external toString: (bigint, ~radix: int=?) => string = "toString"

@deprecated("Use `toString` with `~radix` instead") @send
external toStringWithRadix: (bigint, ~radix: int) => string = "toString"

/**
Returns a string with a language-sensitive representation of this BigInt value.

## Examples

```rescript
BigInt.toString(123n)->assertEqual("123")
```
*/
@send
external toLocaleString: bigint => string = "toLocaleString"

Expand All @@ -140,12 +54,6 @@ external bitwiseNot: bigint => bigint = "%bitnot_bigint"
external shiftLeft: (bigint, bigint) => bigint = "%lslbigint"
external shiftRight: (bigint, bigint) => bigint = "%asrbigint"

/**
`ignore(bigint)` ignores the provided bigint and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
without having to store or process it further.
*/
external ignore: bigint => unit = "%ignore"

@deprecated("Use `&` operator or `bitwiseAnd` instead.")
Expand Down
Loading