diff options
author | Pierre Weis <Pierre.Weis@inria.fr> | 1998-12-02 10:40:33 +0000 |
---|---|---|
committer | Pierre Weis <Pierre.Weis@inria.fr> | 1998-12-02 10:40:33 +0000 |
commit | 73e446d376ef844f45deab1071b79fd048b0cd2d (patch) | |
tree | 19cca209a0ddaefe12237784a21ef10367b27ce3 | |
parent | b83b27899119824923f754caf251f17bc02bae3f (diff) |
Ajout des fonctions int_of_float, float_of_int, char_of_int,
int_of_char, bool_of_string.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2211 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | stdlib/char.ml | 2 | ||||
-rw-r--r-- | stdlib/char.mli | 6 | ||||
-rw-r--r-- | stdlib/pervasives.ml | 6 | ||||
-rw-r--r-- | stdlib/pervasives.mli | 8 |
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" |