Skip to content

Add docstring for Float.equal and Float.compare #7568

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 5 commits into from
Jun 19, 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
34 changes: 17 additions & 17 deletions runtime/Stdlib_Bool.resi
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Converts a boolean to a string.

## Examples
```rescript
Bool.toString(true)->assertEqual("true")
Bool.toString(false)->assertEqual("false")
Bool.toString(true) == "true"
Bool.toString(false) == "false"
```
*/
let toString: bool => string
Expand All @@ -24,9 +24,9 @@ Converts a string to a boolean.

## Examples
```rescript
Bool.fromString("true")->assertEqual(Some(true))
Bool.fromString("false")->assertEqual(Some(false))
Bool.fromString("notAValidBoolean")->assertEqual(None)
Bool.fromString("true") == Some(true)
Bool.fromString("false") == Some(false)
Bool.fromString("notAValidBoolean") == None
```
*/
let fromString: string => option<bool>
Expand All @@ -37,8 +37,8 @@ Throws an `Invalid_argument` exception if the string is not a valid boolean.

## Examples
```rescript
Bool.fromStringOrThrow("true")->assertEqual(true)
Bool.fromStringOrThrow("false")->assertEqual(false)
Bool.fromStringOrThrow("true") == true
Bool.fromStringOrThrow("false") == false
switch Bool.fromStringOrThrow("notAValidBoolean") {
| exception Invalid_argument(_) => assert(true)
| _ => assert(false)
Expand All @@ -54,8 +54,8 @@ if the string is not a valid boolean.

## Examples
```rescript
Bool.fromStringExn("true")->assertEqual(true)
Bool.fromStringExn("false")->assertEqual(false)
Bool.fromStringExn("true") == true
Bool.fromStringExn("false") == false
switch Bool.fromStringExn("notAValidBoolean") {
| exception Invalid_argument(_) => assert(true)
| _ => assert(false)
Expand All @@ -70,10 +70,10 @@ Compares two booleans, returns an `Ordering.t` value.

## Examples
```rescript
Bool.compare(true, true)->assertEqual(Ordering.equal)
Bool.compare(false, false)->assertEqual(Ordering.equal)
Bool.compare(true, false)->assertEqual(Ordering.greater)
Bool.compare(false, true)->assertEqual(Ordering.less)
Bool.compare(true, true) == Ordering.equal
Bool.compare(false, false) == Ordering.equal
Bool.compare(true, false) == Ordering.greater
Bool.compare(false, true) == Ordering.less
```
*/
external compare: (bool, bool) => Stdlib_Ordering.t = "%compare"
Expand All @@ -83,10 +83,10 @@ Checks if two booleans are equal and have the same value.

## Examples
```rescript
Bool.equal(true, true)->assertEqual(true)
Bool.equal(false, false)->assertEqual(true)
Bool.equal(true, false)->assertEqual(false)
Bool.equal(false, true)->assertEqual(false)
Bool.equal(true, true) == true
Bool.equal(false, false) == true
Bool.equal(true, false) == false
Bool.equal(false, true) == false
```
*/
external equal: (bool, bool) => bool = "%equal"
19 changes: 19 additions & 0 deletions runtime/Stdlib_Date.resi
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,27 @@ Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00
@val
external now: unit => msSinceEpoch = "Date.now"

/**
`equal(date1, date2)` checks if two dates represent the same point in time.

## Examples
```rescript
Date.equal(Date.fromString("2023-01-01"), Date.fromString("2023-01-01")) == true
Date.equal(Date.fromString("2023-01-01"), Date.fromString("2023-01-02")) == false
```
*/
let equal: (t, t) => bool

/**
`compare(date1, date2)` compares two dates chronologically, returns an `Ordering.t` value.

## Examples
```rescript
Date.compare(Date.fromString("2023-01-01"), Date.fromString("2023-01-01")) == Ordering.equal
Date.compare(Date.fromString("2023-01-01"), Date.fromString("2023-01-02")) == Ordering.less
Date.compare(Date.fromString("2023-01-02"), Date.fromString("2023-01-01")) == Ordering.greater
```
*/
let compare: (t, t) => Stdlib_Ordering.t

/**
Expand Down
107 changes: 63 additions & 44 deletions runtime/Stdlib_Float.resi
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,27 @@ module Constants: {
external maxValue: float = "Number.MAX_VALUE"
}

/**
Checks if two floating point numbers are equal.

## Examples
```rescript
Float.equal(1.0, 1.0) == true
Float.equal(1.0, 2.0) == false
```
*/
external equal: (float, float) => bool = "%equal"

/**
Compares two floating point numbers, returns an `Ordering.t` value.

## Examples
```rescript
Float.compare(1.0, 1.0) == Ordering.equal
Float.compare(1.0, 2.0) == Ordering.less
Float.compare(2.0, 1.0) == Ordering.greater
```
*/
external compare: (float, float) => Stdlib_Ordering.t = "%compare"

/**
Expand All @@ -139,9 +158,9 @@ See [`isFinite`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
## Examples

```rescript
Float.isFinite(1.0) // true
Float.isFinite(Float.Constants.nan) // false
Float.isFinite(Float.Constants.positiveInfinity) // false
Float.isFinite(1.0) == true
Float.isFinite(Float.Constants.nan) == false
Float.isFinite(Float.Constants.positiveInfinity) == false
```
*/
@val
Expand All @@ -156,11 +175,11 @@ See [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
## Examples

```rescript
Float.parseFloat("1.0") // 1.0
Float.parseFloat(" 3.14 ") // 3.14
Float.parseFloat("3.0") // 3.0
Float.parseFloat("3.14some non-digit characters") // 3.14
Float.parseFloat("error")->Float.isNaN // true
Float.parseFloat("1.0") == 1.0
Float.parseFloat(" 3.14 ") == 3.14
Float.parseFloat("3.0") == 3.0
Float.parseFloat("3.14some non-digit characters") == 3.14
Float.parseFloat("error")->Float.isNaN == true
```
*/
@val
Expand All @@ -177,15 +196,15 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
## Examples

```rescript
Float.parseInt("1.0") // 1.0
Float.parseInt(" 3.14 ") // 3.0
Float.parseInt(3) // 3.0
Float.parseInt("3.14some non-digit characters") // 3.0
Float.parseInt("error")->Float.isNaN // true
Float.parseInt("10.0", ~radix=2) // 2.0
Float.parseInt("15 * 3", ~radix=10) // 15.0
Float.parseInt("12", ~radix=13) // 15.0
Float.parseInt("17", ~radix=40)->Float.isNaN // true
Float.parseInt("1.0") == 1.0
Float.parseInt(" 3.14 ") == 3.0
Float.parseInt(3) == 3.0
Float.parseInt("3.14some non-digit characters") == 3.0
Float.parseInt("error")->Float.isNaN == true
Float.parseInt("10.0", ~radix=2) == 2.0
Float.parseInt("15 * 3", ~radix=10) == 15.0
Float.parseInt("12", ~radix=13) == 15.0
Float.parseInt("17", ~radix=40)->Float.isNaN == true
```
*/
@val
Expand All @@ -202,10 +221,10 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
## Examples

```rescript
Float.parseIntWithRadix("10.0", ~radix=2) // 2.0
Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0
Float.parseIntWithRadix("12", ~radix=13) // 15.0
Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true
Float.parseIntWithRadix("10.0", ~radix=2) == 2.0
Float.parseIntWithRadix("15 * 3", ~radix=10) == 15.0
Float.parseIntWithRadix("12", ~radix=13) == 15.0
Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN == true
```
*/
@deprecated("Use `parseInt` instead") @val
Expand All @@ -220,10 +239,10 @@ See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaSc
## Examples

```rescript
Float.toExponential(1000.0) // "1e+3"
Float.toExponential(-1000.0) // "-1e+3"
Float.toExponential(77.0, ~digits=2) // "7.70e+1"
Float.toExponential(5678.0, ~digits=2) // "5.68e+3"
Float.toExponential(1000.0) == "1e+3"
Float.toExponential(-1000.0) == "-1e+3"
Float.toExponential(77.0, ~digits=2) == "7.70e+1"
Float.toExponential(5678.0, ~digits=2) == "5.68e+3"
```

## Exceptions
Expand All @@ -242,8 +261,8 @@ See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaSc
## Examples

```rescript
Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1"
Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3"
Float.toExponentialWithPrecision(77.0, ~digits=2) == "7.70e+1"
Float.toExponentialWithPrecision(5678.0, ~digits=2) == "5.68e+3"
```

## Exceptions
Expand All @@ -262,10 +281,10 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
## Examples

```rescript
Float.toFixed(123456.0) // "123456.00"
Float.toFixed(10.0) // "10.00"
Float.toFixed(300.0, ~digits=4) // "300.0000"
Float.toFixed(300.0, ~digits=1) // "300.0"
Float.toFixed(123456.0) == "123456"
Float.toFixed(10.0) == "10"
Float.toFixed(300.0, ~digits=4) == "300.0000"
Float.toFixed(300.0, ~digits=1) == "300.0"
```

## Exceptions
Expand All @@ -284,8 +303,8 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
## Examples

```rescript
Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000"
Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0"
Float.toFixedWithPrecision(300.0, ~digits=4) == "300.0000"
Float.toFixedWithPrecision(300.0, ~digits=1) == "300.0"
```

## Exceptions
Expand All @@ -303,10 +322,10 @@ See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
## Examples

```rescript
Float.toPrecision(100.0) // "100"
Float.toPrecision(1.0) // "1"
Float.toPrecision(100.0, ~digits=2) // "1.0e+2"
Float.toPrecision(1.0, ~digits=1) // "1"
Float.toPrecision(100.0) == "100"
Float.toPrecision(1.0) == "1"
Float.toPrecision(100.0, ~digits=2) == "1.0e+2"
Float.toPrecision(1.0, ~digits=1) == "1"
```

## Exceptions
Expand All @@ -326,8 +345,8 @@ See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
## Examples

```rescript
Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2"
Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1"
Float.toPrecisionWithPrecision(100.0, ~digits=2) == "1.0e+2"
Float.toPrecisionWithPrecision(1.0, ~digits=1) == "1"
```

## Exceptions
Expand All @@ -347,8 +366,8 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
## Examples

```rescript
Float.toString(1000.0) // "1000"
Float.toString(-1000.0) // "-1000"
Float.toString(1000.0) == "1000"
Float.toString(-1000.0) == "-1000"
```
*/
@send
Expand All @@ -362,9 +381,9 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
## Examples

```rescript
Float.toStringWithRadix(6.0, ~radix=2) // "110"
Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef"
Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c"
Float.toStringWithRadix(6.0, ~radix=2) == "110"
Float.toStringWithRadix(3735928559.0, ~radix=16) == "deadbeef"
Float.toStringWithRadix(123456.0, ~radix=36) == "2n9c"
```

## Exceptions
Expand Down
Loading