Skip to content

Commit de15950

Browse files
authored
Docstrings for BigInt (#7592)
* docstrings for bigint * fix test
1 parent 50c72c5 commit de15950

File tree

3 files changed

+415
-92
lines changed

3 files changed

+415
-92
lines changed

packages/artifacts.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,9 @@ lib/ocaml/Stdlib_AsyncIterator.resi
938938
lib/ocaml/Stdlib_BigInt.cmi
939939
lib/ocaml/Stdlib_BigInt.cmj
940940
lib/ocaml/Stdlib_BigInt.cmt
941+
lib/ocaml/Stdlib_BigInt.cmti
941942
lib/ocaml/Stdlib_BigInt.res
943+
lib/ocaml/Stdlib_BigInt.resi
942944
lib/ocaml/Stdlib_BigInt64Array.cmi
943945
lib/ocaml/Stdlib_BigInt64Array.cmj
944946
lib/ocaml/Stdlib_BigInt64Array.cmt

runtime/Stdlib_BigInt.res

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,11 @@
1-
/**
2-
Type representing a bigint.
3-
*/
41
type t = bigint
52

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

9-
/**
10-
Parses the given `string` into a `bigint` using JavaScript semantics. Return the
11-
number as a `bigint` if successfully parsed. Throws a syntax exception otherwise.
12-
13-
## Examples
14-
15-
```rescript
16-
BigInt.fromStringOrThrow("123")->assertEqual(123n)
17-
18-
BigInt.fromStringOrThrow("")->assertEqual(0n)
19-
20-
BigInt.fromStringOrThrow("0x11")->assertEqual(17n)
21-
22-
BigInt.fromStringOrThrow("0b11")->assertEqual(3n)
23-
24-
BigInt.fromStringOrThrow("0o11")->assertEqual(9n)
25-
26-
/* catch exception */
27-
switch BigInt.fromStringOrThrow("a") {
28-
| exception JsExn(_error) => assert(true)
29-
| _bigInt => assert(false)
30-
}
31-
```
32-
*/
336
@val
347
external fromStringOrThrow: string => bigint = "BigInt"
358

36-
/**
37-
Parses the given `string` into a `bigint` using JavaScript semantics. Returns
38-
`Some(bigint)` if the string can be parsed, `None` otherwise.
39-
40-
## Examples
41-
42-
```rescript
43-
BigInt.fromString("123")->assertEqual(Some(123n))
44-
45-
BigInt.fromString("")->assertEqual(Some(0n))
46-
47-
BigInt.fromString("0x11")->assertEqual(Some(17n))
48-
49-
BigInt.fromString("0b11")->assertEqual(Some(3n))
50-
51-
BigInt.fromString("0o11")->assertEqual(Some(9n))
52-
53-
BigInt.fromString("invalid")->assertEqual(None)
54-
```
55-
*/
569
let fromString = (value: string) => {
5710
try Some(fromStringOrThrow(value)) catch {
5811
| _ => None
@@ -64,26 +17,6 @@ external fromStringExn: string => bigint = "BigInt"
6417

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

67-
/**
68-
Converts a `float` to a `bigint` using JavaScript semantics.
69-
Throws an exception if the float is not an integer or is infinite/NaN.
70-
71-
## Examples
72-
73-
```rescript
74-
BigInt.fromFloatOrThrow(123.0)->assertEqual(123n)
75-
76-
BigInt.fromFloatOrThrow(0.0)->assertEqual(0n)
77-
78-
BigInt.fromFloatOrThrow(-456.0)->assertEqual(-456n)
79-
80-
/* This will throw an exception */
81-
switch BigInt.fromFloatOrThrow(123.5) {
82-
| exception JsExn(_error) => assert(true)
83-
| _bigInt => assert(false)
84-
}
85-
```
86-
*/
8720
@val
8821
external fromFloatOrThrow: float => bigint = "BigInt"
8922

@@ -93,31 +26,12 @@ let fromFloat = (value: float) => {
9326
}
9427
}
9528

96-
/**
97-
Formats a `bigint` as a string. Return a `string` representing the given value.
98-
See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.
99-
100-
## Examples
101-
102-
```rescript
103-
BigInt.toString(123n)->assertEqual("123")
104-
```
105-
*/
10629
@send
10730
external toString: (bigint, ~radix: int=?) => string = "toString"
10831

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

112-
/**
113-
Returns a string with a language-sensitive representation of this BigInt value.
114-
115-
## Examples
116-
117-
```rescript
118-
BigInt.toString(123n)->assertEqual("123")
119-
```
120-
*/
12135
@send
12236
external toLocaleString: bigint => string = "toLocaleString"
12337

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

143-
/**
144-
`ignore(bigint)` ignores the provided bigint and returns unit.
145-
146-
This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
147-
without having to store or process it further.
148-
*/
14957
external ignore: bigint => unit = "%ignore"
15058

15159
@deprecated("Use `&` operator or `bitwiseAnd` instead.")

0 commit comments

Comments
 (0)