Skip to content

Commit 4bb5902

Browse files
committed
Add Float.equal, Float.compare
1 parent 50ea8d5 commit 4bb5902

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/Core__Float.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33

44
var Constants = {};
55

6+
function equal(a, b) {
7+
return a === b;
8+
}
9+
10+
function compare(a, b) {
11+
if (a === b) {
12+
return 0;
13+
} else if (a > b) {
14+
return 1;
15+
} else {
16+
return -1;
17+
}
18+
}
19+
620
function fromString(i) {
721
var i$1 = parseFloat(i);
822
if (isNaN(i$1)) {
@@ -14,6 +28,8 @@ function fromString(i) {
1428

1529
export {
1630
Constants ,
31+
equal ,
32+
compare ,
1733
fromString ,
1834
}
1935
/* No side effect */

src/Core__Float.res

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ module Constants = {
77
@val external maxValue: float = "Number.MAX_VALUE"
88
}
99

10+
let equal = (a: float, b: float) => a === b
11+
12+
let compare = (a: float, b: float) =>
13+
if a === b {
14+
0
15+
} else if a > b {
16+
1
17+
} else {
18+
-1
19+
}
20+
1021
@val external isNaN: float => bool = "isNaN"
1122
@val external isFinite: float => bool = "isFinite"
1223
@val external parseFloat: 'a => float = "parseFloat"

src/Core__Float.resi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ module Constants: {
109109
external maxValue: float = "Number.MAX_VALUE"
110110
}
111111

112+
let equal: (float, float) => bool
113+
114+
let compare: (float, float) => int
115+
112116
/**
113117
`isNaN(v)` tests if the given `v` is `NaN`.
114118
See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN.

0 commit comments

Comments
 (0)