summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stdlib/char.ml2
-rw-r--r--stdlib/char.mli6
-rw-r--r--stdlib/pervasives.ml6
-rw-r--r--stdlib/pervasives.mli8
4 files changed, 21 insertions, 1 deletions
diff --git a/stdlib/char.ml b/stdlib/char.ml
index deb477cb0..2d5bb2458 100644
--- a/stdlib/char.ml
+++ b/stdlib/char.ml
@@ -14,10 +14,12 @@
(* Character operations *)
external code: char -> int = "%identity"
+external int_of_char: char -> int = "%identity"
external unsafe_chr: int -> char = "%identity"
let chr n =
if n < 0 or n > 255 then invalid_arg "Char.chr" else unsafe_chr n
+let char_of_int = chr
external is_printable: char -> bool = "is_printable"
diff --git a/stdlib/char.mli b/stdlib/char.mli
index 6435d425d..64544621f 100644
--- a/stdlib/char.mli
+++ b/stdlib/char.mli
@@ -13,12 +13,16 @@
(* Module [Char]: character operations *)
-external code: char -> int = "%identity"
+external code : char -> int = "%identity"
(* Return the ASCII code of the argument. *)
+external int_of_char : char -> int = "%identity"
+ (* Alias of the [code] function above. *)
val chr: int -> char
(* Return the character with the given ASCII code.
Raise [Invalid_argument "Char.chr"] if the argument is
outside the range 0--255. *)
+val char_of_int : int -> char
+ (* Alias of the [chr] function above. *)
val escaped : char -> string
(* Return a string representing the given character,
with special characters escaped following the lexical conventions
diff --git a/stdlib/pervasives.ml b/stdlib/pervasives.ml
index 83b591c07..9819c1c5c 100644
--- a/stdlib/pervasives.ml
+++ b/stdlib/pervasives.ml
@@ -103,7 +103,9 @@ external frexp : float -> float * int = "frexp_float"
external ldexp : float -> int -> float = "ldexp_float"
external modf : float -> float * float = "modf_float" "modf"
external float : int -> float = "%floatofint"
+external float_of_int : int -> float = "%floatofint"
external truncate : float -> int = "%intoffloat"
+external int_of_float : float -> int = "%intoffloat"
(* String operations -- more in module String *)
@@ -131,6 +133,10 @@ external format_float: string -> float -> string = "format_float"
let string_of_bool b =
if b then "true" else "false"
+let bool_of_string = function
+ | "true" -> true
+ | "false" -> false
+ | _ -> invalid_arg "string_of_bool"
let string_of_int n =
format_int "%d" n
diff --git a/stdlib/pervasives.mli b/stdlib/pervasives.mli
index 359572a9b..363eff8cd 100644
--- a/stdlib/pervasives.mli
+++ b/stdlib/pervasives.mli
@@ -277,10 +277,14 @@ external modf : float -> float * float = "modf_float" "modf"
part of [f]. *)
external float : int -> float = "%floatofint"
(* Convert an integer to floating-point. *)
+external float_of_int : int -> float = "%floatofint"
+ (* Alias of [float] above. *)
external truncate : float -> int = "%intoffloat"
(* Truncate the given floating-point number to an integer.
The result is unspecified if it falls outside the
range of representable integers. *)
+external int_of_float : float -> int = "%intoffloat"
+ (* Alias of [truncate] above. *)
(*** String operations *)
@@ -293,6 +297,10 @@ val (^) : string -> string -> string
val string_of_bool : bool -> string
(* Return the string representation of a boolean. *)
+val bool_of_string : string -> bool
+ (* Convert the given string to a boolean.
+ Raise [Invalid_argument "bool_of_string"] if the string is not
+ ["true"] or ["false"]. *)
val string_of_int : int -> string
(* Return the string representation of an integer, in decimal. *)
external int_of_string : string -> int = "int_of_string"