Skip to content

Commit eb2c71b

Browse files
authored
Add docstring for Float.equal and Float.compare (#7568)
* Add docstring for Float.equal and Float.compare * Use == in Bool examples * Use == in Float test * Update completion snapshot * Add Date as well
1 parent 2c0a4eb commit eb2c71b

File tree

4 files changed

+107
-69
lines changed

4 files changed

+107
-69
lines changed

runtime/Stdlib_Bool.resi

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Converts a boolean to a string.
1313
1414
## Examples
1515
```rescript
16-
Bool.toString(true)->assertEqual("true")
17-
Bool.toString(false)->assertEqual("false")
16+
Bool.toString(true) == "true"
17+
Bool.toString(false) == "false"
1818
```
1919
*/
2020
let toString: bool => string
@@ -24,9 +24,9 @@ Converts a string to a boolean.
2424
2525
## Examples
2626
```rescript
27-
Bool.fromString("true")->assertEqual(Some(true))
28-
Bool.fromString("false")->assertEqual(Some(false))
29-
Bool.fromString("notAValidBoolean")->assertEqual(None)
27+
Bool.fromString("true") == Some(true)
28+
Bool.fromString("false") == Some(false)
29+
Bool.fromString("notAValidBoolean") == None
3030
```
3131
*/
3232
let fromString: string => option<bool>
@@ -37,8 +37,8 @@ Throws an `Invalid_argument` exception if the string is not a valid boolean.
3737
3838
## Examples
3939
```rescript
40-
Bool.fromStringOrThrow("true")->assertEqual(true)
41-
Bool.fromStringOrThrow("false")->assertEqual(false)
40+
Bool.fromStringOrThrow("true") == true
41+
Bool.fromStringOrThrow("false") == false
4242
switch Bool.fromStringOrThrow("notAValidBoolean") {
4343
| exception Invalid_argument(_) => assert(true)
4444
| _ => assert(false)
@@ -54,8 +54,8 @@ if the string is not a valid boolean.
5454
5555
## Examples
5656
```rescript
57-
Bool.fromStringExn("true")->assertEqual(true)
58-
Bool.fromStringExn("false")->assertEqual(false)
57+
Bool.fromStringExn("true") == true
58+
Bool.fromStringExn("false") == false
5959
switch Bool.fromStringExn("notAValidBoolean") {
6060
| exception Invalid_argument(_) => assert(true)
6161
| _ => assert(false)
@@ -70,10 +70,10 @@ Compares two booleans, returns an `Ordering.t` value.
7070
7171
## Examples
7272
```rescript
73-
Bool.compare(true, true)->assertEqual(Ordering.equal)
74-
Bool.compare(false, false)->assertEqual(Ordering.equal)
75-
Bool.compare(true, false)->assertEqual(Ordering.greater)
76-
Bool.compare(false, true)->assertEqual(Ordering.less)
73+
Bool.compare(true, true) == Ordering.equal
74+
Bool.compare(false, false) == Ordering.equal
75+
Bool.compare(true, false) == Ordering.greater
76+
Bool.compare(false, true) == Ordering.less
7777
```
7878
*/
7979
external compare: (bool, bool) => Stdlib_Ordering.t = "%compare"
@@ -83,10 +83,10 @@ Checks if two booleans are equal and have the same value.
8383
8484
## Examples
8585
```rescript
86-
Bool.equal(true, true)->assertEqual(true)
87-
Bool.equal(false, false)->assertEqual(true)
88-
Bool.equal(true, false)->assertEqual(false)
89-
Bool.equal(false, true)->assertEqual(false)
86+
Bool.equal(true, true) == true
87+
Bool.equal(false, false) == true
88+
Bool.equal(true, false) == false
89+
Bool.equal(false, true) == false
9090
```
9191
*/
9292
external equal: (bool, bool) => bool = "%equal"

runtime/Stdlib_Date.resi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,27 @@ Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00
428428
@val
429429
external now: unit => msSinceEpoch = "Date.now"
430430

431+
/**
432+
`equal(date1, date2)` checks if two dates represent the same point in time.
433+
434+
## Examples
435+
```rescript
436+
Date.equal(Date.fromString("2023-01-01"), Date.fromString("2023-01-01")) == true
437+
Date.equal(Date.fromString("2023-01-01"), Date.fromString("2023-01-02")) == false
438+
```
439+
*/
431440
let equal: (t, t) => bool
432441

442+
/**
443+
`compare(date1, date2)` compares two dates chronologically, returns an `Ordering.t` value.
444+
445+
## Examples
446+
```rescript
447+
Date.compare(Date.fromString("2023-01-01"), Date.fromString("2023-01-01")) == Ordering.equal
448+
Date.compare(Date.fromString("2023-01-01"), Date.fromString("2023-01-02")) == Ordering.less
449+
Date.compare(Date.fromString("2023-01-02"), Date.fromString("2023-01-01")) == Ordering.greater
450+
```
451+
*/
433452
let compare: (t, t) => Stdlib_Ordering.t
434453

435454
/**

runtime/Stdlib_Float.resi

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,27 @@ module Constants: {
114114
external maxValue: float = "Number.MAX_VALUE"
115115
}
116116

117+
/**
118+
Checks if two floating point numbers are equal.
119+
120+
## Examples
121+
```rescript
122+
Float.equal(1.0, 1.0) == true
123+
Float.equal(1.0, 2.0) == false
124+
```
125+
*/
117126
external equal: (float, float) => bool = "%equal"
118127

128+
/**
129+
Compares two floating point numbers, returns an `Ordering.t` value.
130+
131+
## Examples
132+
```rescript
133+
Float.compare(1.0, 1.0) == Ordering.equal
134+
Float.compare(1.0, 2.0) == Ordering.less
135+
Float.compare(2.0, 1.0) == Ordering.greater
136+
```
137+
*/
119138
external compare: (float, float) => Stdlib_Ordering.t = "%compare"
120139

121140
/**
@@ -139,9 +158,9 @@ See [`isFinite`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
139158
## Examples
140159
141160
```rescript
142-
Float.isFinite(1.0) // true
143-
Float.isFinite(Float.Constants.nan) // false
144-
Float.isFinite(Float.Constants.positiveInfinity) // false
161+
Float.isFinite(1.0) == true
162+
Float.isFinite(Float.Constants.nan) == false
163+
Float.isFinite(Float.Constants.positiveInfinity) == false
145164
```
146165
*/
147166
@val
@@ -156,11 +175,11 @@ See [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
156175
## Examples
157176
158177
```rescript
159-
Float.parseFloat("1.0") // 1.0
160-
Float.parseFloat(" 3.14 ") // 3.14
161-
Float.parseFloat("3.0") // 3.0
162-
Float.parseFloat("3.14some non-digit characters") // 3.14
163-
Float.parseFloat("error")->Float.isNaN // true
178+
Float.parseFloat("1.0") == 1.0
179+
Float.parseFloat(" 3.14 ") == 3.14
180+
Float.parseFloat("3.0") == 3.0
181+
Float.parseFloat("3.14some non-digit characters") == 3.14
182+
Float.parseFloat("error")->Float.isNaN == true
164183
```
165184
*/
166185
@val
@@ -177,15 +196,15 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
177196
## Examples
178197
179198
```rescript
180-
Float.parseInt("1.0") // 1.0
181-
Float.parseInt(" 3.14 ") // 3.0
182-
Float.parseInt(3) // 3.0
183-
Float.parseInt("3.14some non-digit characters") // 3.0
184-
Float.parseInt("error")->Float.isNaN // true
185-
Float.parseInt("10.0", ~radix=2) // 2.0
186-
Float.parseInt("15 * 3", ~radix=10) // 15.0
187-
Float.parseInt("12", ~radix=13) // 15.0
188-
Float.parseInt("17", ~radix=40)->Float.isNaN // true
199+
Float.parseInt("1.0") == 1.0
200+
Float.parseInt(" 3.14 ") == 3.0
201+
Float.parseInt(3) == 3.0
202+
Float.parseInt("3.14some non-digit characters") == 3.0
203+
Float.parseInt("error")->Float.isNaN == true
204+
Float.parseInt("10.0", ~radix=2) == 2.0
205+
Float.parseInt("15 * 3", ~radix=10) == 15.0
206+
Float.parseInt("12", ~radix=13) == 15.0
207+
Float.parseInt("17", ~radix=40)->Float.isNaN == true
189208
```
190209
*/
191210
@val
@@ -202,10 +221,10 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
202221
## Examples
203222
204223
```rescript
205-
Float.parseIntWithRadix("10.0", ~radix=2) // 2.0
206-
Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0
207-
Float.parseIntWithRadix("12", ~radix=13) // 15.0
208-
Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true
224+
Float.parseIntWithRadix("10.0", ~radix=2) == 2.0
225+
Float.parseIntWithRadix("15 * 3", ~radix=10) == 15.0
226+
Float.parseIntWithRadix("12", ~radix=13) == 15.0
227+
Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN == true
209228
```
210229
*/
211230
@deprecated("Use `parseInt` instead") @val
@@ -220,10 +239,10 @@ See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaSc
220239
## Examples
221240
222241
```rescript
223-
Float.toExponential(1000.0) // "1e+3"
224-
Float.toExponential(-1000.0) // "-1e+3"
225-
Float.toExponential(77.0, ~digits=2) // "7.70e+1"
226-
Float.toExponential(5678.0, ~digits=2) // "5.68e+3"
242+
Float.toExponential(1000.0) == "1e+3"
243+
Float.toExponential(-1000.0) == "-1e+3"
244+
Float.toExponential(77.0, ~digits=2) == "7.70e+1"
245+
Float.toExponential(5678.0, ~digits=2) == "5.68e+3"
227246
```
228247
229248
## Exceptions
@@ -242,8 +261,8 @@ See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaSc
242261
## Examples
243262
244263
```rescript
245-
Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1"
246-
Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3"
264+
Float.toExponentialWithPrecision(77.0, ~digits=2) == "7.70e+1"
265+
Float.toExponentialWithPrecision(5678.0, ~digits=2) == "5.68e+3"
247266
```
248267
249268
## Exceptions
@@ -262,10 +281,10 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
262281
## Examples
263282
264283
```rescript
265-
Float.toFixed(123456.0) // "123456.00"
266-
Float.toFixed(10.0) // "10.00"
267-
Float.toFixed(300.0, ~digits=4) // "300.0000"
268-
Float.toFixed(300.0, ~digits=1) // "300.0"
284+
Float.toFixed(123456.0) == "123456"
285+
Float.toFixed(10.0) == "10"
286+
Float.toFixed(300.0, ~digits=4) == "300.0000"
287+
Float.toFixed(300.0, ~digits=1) == "300.0"
269288
```
270289
271290
## Exceptions
@@ -284,8 +303,8 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
284303
## Examples
285304
286305
```rescript
287-
Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000"
288-
Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0"
306+
Float.toFixedWithPrecision(300.0, ~digits=4) == "300.0000"
307+
Float.toFixedWithPrecision(300.0, ~digits=1) == "300.0"
289308
```
290309
291310
## Exceptions
@@ -303,10 +322,10 @@ See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
303322
## Examples
304323
305324
```rescript
306-
Float.toPrecision(100.0) // "100"
307-
Float.toPrecision(1.0) // "1"
308-
Float.toPrecision(100.0, ~digits=2) // "1.0e+2"
309-
Float.toPrecision(1.0, ~digits=1) // "1"
325+
Float.toPrecision(100.0) == "100"
326+
Float.toPrecision(1.0) == "1"
327+
Float.toPrecision(100.0, ~digits=2) == "1.0e+2"
328+
Float.toPrecision(1.0, ~digits=1) == "1"
310329
```
311330
312331
## Exceptions
@@ -326,8 +345,8 @@ See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
326345
## Examples
327346
328347
```rescript
329-
Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2"
330-
Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1"
348+
Float.toPrecisionWithPrecision(100.0, ~digits=2) == "1.0e+2"
349+
Float.toPrecisionWithPrecision(1.0, ~digits=1) == "1"
331350
```
332351
333352
## Exceptions
@@ -347,8 +366,8 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
347366
## Examples
348367
349368
```rescript
350-
Float.toString(1000.0) // "1000"
351-
Float.toString(-1000.0) // "-1000"
369+
Float.toString(1000.0) == "1000"
370+
Float.toString(-1000.0) == "-1000"
352371
```
353372
*/
354373
@send
@@ -362,9 +381,9 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
362381
## Examples
363382
364383
```rescript
365-
Float.toStringWithRadix(6.0, ~radix=2) // "110"
366-
Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef"
367-
Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c"
384+
Float.toStringWithRadix(6.0, ~radix=2) == "110"
385+
Float.toStringWithRadix(3735928559.0, ~radix=16) == "deadbeef"
386+
Float.toStringWithRadix(123456.0, ~radix=36) == "2n9c"
368387
```
369388
370389
## Exceptions

0 commit comments

Comments
 (0)