File tree 3 files changed +21
-3
lines changed
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,18 @@ function floor(f) {
7
7
return Math . floor ( f ) | 0 ;
8
8
}
9
9
10
+ function ceil ( f ) {
11
+ return Math . ceil ( f ) | 0 ;
12
+ }
13
+
10
14
function random ( min , max ) {
11
15
var f = Math . random ( ) * ( max - min | 0 ) ;
12
16
return ( Math . floor ( f ) | 0 ) + min | 0 ;
13
17
}
14
18
15
19
var Int = {
16
20
floor : floor ,
21
+ ceil : ceil ,
17
22
random : random
18
23
} ;
19
24
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ module Int = {
57
57
@val external pow : (int , ~exp : int ) => int = "Math.pow"
58
58
@val external sign : int => int = "Math.sign"
59
59
let floor : float => int = f => f -> floor -> Core__Float .toInt
60
+ let ceil : float => int = f => f -> ceil -> Core__Float .toInt
60
61
let random : (int , int ) => int = (min , max ) =>
61
62
floor (random () *. Core__Int .toFloat (max - min )) + min
62
63
}
Original file line number Diff line number Diff line change @@ -279,7 +279,6 @@ module Int: {
279
279
280
280
/**
281
281
floor(v) returns the largest `int` less than or equal to the argument;
282
- the result is pinned to the range of the `int` data type: -2147483648 to 2147483647.
283
282
See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
284
283
on MDN.
285
284
@@ -289,12 +288,25 @@ module Int: {
289
288
Math.Int.floor(3.7) == 3
290
289
Math.Int.floor(3.0) == 3
291
290
Math.Int.floor(-3.1) == -4
292
- Math.Int.floor(-1.0e15) == -2147483648
293
- Math.Int.floor(1.0e15) == 2147483647
294
291
```
295
292
*/
296
293
let floor: float => int
297
294
295
+ /**
296
+ ceil(v) returns the smallest `int` greater than or equal to the argument;
297
+ See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
298
+ on MDN.
299
+
300
+ ## Examples
301
+
302
+ ```rescript
303
+ Math.Int.ceil(3.7) == 4
304
+ Math.Int.ceil(3.0) == 3
305
+ Math.Int.ceil(-3.1) == -3
306
+ ```
307
+ */
308
+ let ceil: float => int
309
+
298
310
/**
299
311
`random(minVal, maxVal)` returns a random integer number in the half-closed interval [minVal, maxVal).
300
312
See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
You can’t perform that action at this time.
0 commit comments