Skip to content

Commit c2dd6d5

Browse files
adhi2714zth
authored andcommitted
added floor_int to Core__Math
1 parent 58efa5c commit c2dd6d5

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/Core__Math.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ var Constants = {};
55

66
var Int = {};
77

8+
function floor_int(f) {
9+
return Math.floor(f) | 0;
10+
}
11+
812
function random_int(min, max) {
9-
return (Math.floor(Math.random() * (max - min | 0)) | 0) + min | 0;
13+
var f = Math.random() * (max - min | 0);
14+
return (Math.floor(f) | 0) + min | 0;
1015
}
1116

1217
export {
1318
Constants ,
1419
Int ,
20+
floor_int ,
1521
random_int ,
1622
}
1723
/* No side effect */

src/Core__Math.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ module Int = {
5858
@val external tanh: float => float = "Math.tanh"
5959
@val external trunc: float => float = "Math.trunc"
6060

61+
let floor_int: float => int = f => f->floor->Core__Float.toInt
62+
6163
let random_int: (int, int) => int = (min, max) =>
62-
floor(random() *. Core__Int.toFloat(max - min))->Core__Float.toInt + min
64+
floor_int(random() *. Core__Int.toFloat(max - min)) + min

src/Core__Math.resi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,6 @@ Math.trunc(42.84) // 42.0
846846
@val
847847
external trunc: float => float = "Math.trunc"
848848

849+
let floor_int: float => int
850+
849851
let random_int: (int, int) => int

0 commit comments

Comments
 (0)