|
22 | 22 | * along with this program; if not, write to the Free Software
|
23 | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
|
24 | 24 |
|
25 |
| -(** [`Belt.Int`]() |
26 |
| - Utililites for Int |
| 25 | +(** |
| 26 | + This module includes convenience methods for handling `int` types. |
27 | 27 | *)
|
28 | 28 |
|
| 29 | +(** |
| 30 | + Converts a given `int` to a `float`. |
| 31 | +
|
| 32 | + ```res example |
| 33 | + Js.log(Belt.Int.toFloat(1) === 1.0) /* true */ |
| 34 | + ``` |
| 35 | +*) |
29 | 36 | external toFloat: int -> float = "%identity"
|
30 | 37 |
|
| 38 | +(** |
| 39 | + Converts a given `float` to an `int`. |
| 40 | +
|
| 41 | + ```res example |
| 42 | + Js.log(Belt.Int.fromFloat(1.0) === 1) /* true */ |
| 43 | + ``` |
| 44 | +*) |
31 | 45 | external fromFloat: float -> int = "%intoffloat"
|
32 | 46 |
|
| 47 | +(** |
| 48 | + Converts a given `string` to an `int`. Returns `Some(int)` when the input is a number, `None` otherwise. |
| 49 | +
|
| 50 | + ```res example |
| 51 | + Js.log(Belt.Int.fromString("1") === Some(1)) /* true */ |
| 52 | + ``` |
| 53 | +*) |
33 | 54 | val fromString: string -> int option
|
34 | 55 |
|
| 56 | +(** |
| 57 | + Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood. |
| 58 | +
|
| 59 | + ```res example |
| 60 | + Js.log(Belt.Int.toString(1) === "1") /* true */ |
| 61 | + ``` |
| 62 | +*) |
35 | 63 | external toString: int -> string = "String" [@@bs.val]
|
36 | 64 |
|
| 65 | +(** |
| 66 | + Addition of two `int` values. Same as the addition from `Pervasives`. |
| 67 | +
|
| 68 | + ```res example |
| 69 | + open Belt.Int |
| 70 | + Js.log(2 + 2 === 4) /* true */ |
| 71 | + ``` |
| 72 | +*) |
37 | 73 | external ( + ) : int -> int -> int = "%addint"
|
38 | 74 |
|
| 75 | +(** |
| 76 | + Subtraction of two `int` values. Same as the subtraction from `Pervasives`. |
| 77 | +
|
| 78 | + ```res example |
| 79 | + open Belt.Int |
| 80 | + Js.log(2 - 1 === 1) /* true */ |
| 81 | + ``` |
| 82 | +*) |
39 | 83 | external ( - ) : int -> int -> int = "%subint"
|
40 | 84 |
|
| 85 | +(** |
| 86 | + Multiplication of two `int` values. Same as the multiplication from `Pervasives`. |
| 87 | +
|
| 88 | + ```res example |
| 89 | + open Belt.Int |
| 90 | + Js.log(2 * 2 === 4) /* true */ |
| 91 | + ``` |
| 92 | +*) |
41 | 93 | external ( * ) : int -> int -> int = "%mulint"
|
42 | 94 |
|
| 95 | +(** |
| 96 | + Division of two `int` values. Same as the division from `Pervasives`. |
| 97 | +
|
| 98 | + ```res example |
| 99 | + open Belt.Int |
| 100 | + Js.log(4 / 2 === 2); /* true */ |
| 101 | + ``` |
| 102 | +*) |
43 | 103 | external ( / ) : int -> int -> int = "%divint"
|
0 commit comments