@@ -114,8 +114,27 @@ module Constants: {
114
114
external maxValue : float = "Number.MAX_VALUE"
115
115
}
116
116
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
+ */
117
126
external equal : (float , float ) => bool = "%equal"
118
127
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
+ */
119
138
external compare : (float , float ) => Stdlib_Ordering .t = "%compare"
120
139
121
140
/**
@@ -139,9 +158,9 @@ See [`isFinite`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
139
158
## Examples
140
159
141
160
```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
145
164
```
146
165
*/
147
166
@val
@@ -156,11 +175,11 @@ See [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
156
175
## Examples
157
176
158
177
```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
164
183
```
165
184
*/
166
185
@val
@@ -177,15 +196,15 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
177
196
## Examples
178
197
179
198
```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
189
208
```
190
209
*/
191
210
@val
@@ -202,10 +221,10 @@ See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen
202
221
## Examples
203
222
204
223
```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
209
228
```
210
229
*/
211
230
@deprecated ("Use `parseInt` instead" ) @val
@@ -220,10 +239,10 @@ See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaSc
220
239
## Examples
221
240
222
241
```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"
227
246
```
228
247
229
248
## Exceptions
@@ -242,8 +261,8 @@ See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaSc
242
261
## Examples
243
262
244
263
```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"
247
266
```
248
267
249
268
## Exceptions
@@ -262,10 +281,10 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
262
281
## Examples
263
282
264
283
```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"
269
288
```
270
289
271
290
## Exceptions
@@ -284,8 +303,8 @@ See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
284
303
## Examples
285
304
286
305
```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"
289
308
```
290
309
291
310
## Exceptions
@@ -303,10 +322,10 @@ See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
303
322
## Examples
304
323
305
324
```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"
310
329
```
311
330
312
331
## Exceptions
@@ -326,8 +345,8 @@ See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
326
345
## Examples
327
346
328
347
```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"
331
350
```
332
351
333
352
## Exceptions
@@ -347,8 +366,8 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
347
366
## Examples
348
367
349
368
```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"
352
371
```
353
372
*/
354
373
@send
@@ -362,9 +381,9 @@ See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/
362
381
## Examples
363
382
364
383
```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"
368
387
```
369
388
370
389
## Exceptions
0 commit comments