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-0dff7051ff02master
parent
b83b278991
commit
73e446d376
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue