File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,19 @@ var Constants = {};
5
5
6
6
var Int = { } ;
7
7
8
+ function floor_int ( f ) {
9
+ return Math . floor ( f ) | 0 ;
10
+ }
11
+
8
12
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 ;
10
15
}
11
16
12
17
export {
13
18
Constants ,
14
19
Int ,
20
+ floor_int ,
15
21
random_int ,
16
22
}
17
23
/* No side effect */
Original file line number Diff line number Diff line change @@ -58,5 +58,7 @@ module Int = {
58
58
@val external tanh : float => float = "Math.tanh"
59
59
@val external trunc : float => float = "Math.trunc"
60
60
61
+ let floor_int : float => int = f => f -> floor -> Core__Float .toInt
62
+
61
63
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
Original file line number Diff line number Diff line change @@ -846,4 +846,6 @@ Math.trunc(42.84) // 42.0
846
846
@val
847
847
external trunc : float => float = "Math.trunc"
848
848
849
+ let floor_int : float => int
850
+
849
851
let random_int : (int , int ) => int
You can’t perform that action at this time.
0 commit comments