|
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.Float`]() |
26 |
| - Utililites for Float |
27 |
| -*) |
| 25 | +(** This module includes convenience methods for handling `float` types. *) |
28 | 26 |
|
29 | 27 | external toInt: float -> int = "%intoffloat"
|
| 28 | +(** |
| 29 | +Converts a given `float` to an `int`. |
| 30 | +
|
| 31 | +```res example |
| 32 | +Js.log(Belt.Float.toInt(1.0) === 1) /* true */ |
| 33 | +``` |
| 34 | +*) |
30 | 35 |
|
31 | 36 | external fromInt: int -> float = "%identity"
|
| 37 | +(** |
| 38 | + Converts a given `int` to a `float`. |
| 39 | +
|
| 40 | + ```res example |
| 41 | + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ |
| 42 | + ``` |
| 43 | +*) |
32 | 44 |
|
33 | 45 | val fromString: string -> float option
|
| 46 | +(** |
| 47 | + Converts a given `string` to a `float`. Returns `Some(float)` when the input is a number, `None` otherwise. |
| 48 | +
|
| 49 | + ```res example |
| 50 | + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ |
| 51 | + ``` |
| 52 | +*) |
| 53 | + |
34 | 54 |
|
35 | 55 | external toString: float -> string = "String" [@@bs.val]
|
| 56 | +(** |
| 57 | + Converts a given `float` to a `string`. Uses the JavaScript `String` constructor under the hood. |
| 58 | +
|
| 59 | + ```res example |
| 60 | + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ |
| 61 | + ``` |
| 62 | +*) |
36 | 63 |
|
37 | 64 | external ( + ) : float -> float -> float = "%addfloat"
|
| 65 | +(** |
| 66 | + Addition of two `float` values. |
| 67 | + Can be opened in a module to avoid dot-notation (`+.`), however this yields a shadow warning (Warning number 44) in the default configuration. |
| 68 | +
|
| 69 | + ```res example |
| 70 | + open Belt.Float |
| 71 | + Js.log(2.0 + 2.0 === 4.0) /* true */ |
| 72 | + ``` |
| 73 | +*) |
38 | 74 |
|
39 | 75 | external ( - ) : float -> float -> float = "%subfloat"
|
| 76 | +(** |
| 77 | + Subtraction of two `float` values. |
| 78 | + Can be opened in a module to avoid dot-notation (`-.`), however this yields a shadow warning (Warning number 44) in the default configuration. |
| 79 | +
|
| 80 | + ```res example |
| 81 | + open Belt.Float |
| 82 | + Js.log(2.0 - 1.0 === 1.0) /* true */ |
| 83 | + ``` |
| 84 | +*) |
40 | 85 |
|
41 | 86 | external ( * ) : float -> float -> float = "%mulfloat"
|
| 87 | +(** |
| 88 | + Multiplication of two `float` values. |
| 89 | + Can be opened in a module to avoid dot-notation (`*.`), however this yields a shadow warning (Warning number 44) in the default configuration. |
| 90 | +
|
| 91 | + ```res example |
| 92 | + open Belt.Float |
| 93 | + Js.log(2.0 * 2.0 === 4.0) /* true */ |
| 94 | + ``` |
| 95 | +*) |
42 | 96 |
|
43 | 97 | external ( / ) : float -> float -> float = "%divfloat"
|
| 98 | +(** |
| 99 | + Division of two `float` values. |
| 100 | + Can be opened in a module to avoid dot-notation (`/.`), however this yields a shadow warning (Warning number 44) in the default configuration. |
| 101 | +
|
| 102 | + ```res example |
| 103 | + open Belt.Float |
| 104 | + Js.log(4.0 / 2.0 === 2.0) /* true */ |
| 105 | + ``` |
| 106 | +*) |
0 commit comments