mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
add CCBool.{to,of}_int
This commit is contained in:
parent
df9bbb8746
commit
70d7dd234d
2 changed files with 25 additions and 2 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
(* This file is free software, part of containers. See file "license" for more details. *)
|
(* This file is free software, part of containers. See file "license" for more details. *)
|
||||||
|
|
||||||
open CCShims_
|
open CCShims_
|
||||||
|
|
@ -9,6 +8,23 @@ let equal (a:bool) b = Stdlib.(=) a b
|
||||||
|
|
||||||
let compare (a:bool) b = Stdlib.compare a b
|
let compare (a:bool) b = Stdlib.compare a b
|
||||||
|
|
||||||
|
let to_int (x:bool) : int = if x then 1 else 0
|
||||||
|
|
||||||
|
(*$=
|
||||||
|
1 (to_int true)
|
||||||
|
0 (to_int false)
|
||||||
|
*)
|
||||||
|
|
||||||
|
let of_int x : t = x<>0
|
||||||
|
|
||||||
|
(*$=
|
||||||
|
true (of_int 1)
|
||||||
|
false (of_int 0)
|
||||||
|
true (of_int 42)
|
||||||
|
true (of_int max_int)
|
||||||
|
true (of_int min_int)
|
||||||
|
*)
|
||||||
|
|
||||||
let negate = not
|
let negate = not
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
(* This file is free software, part of containers. See file "license" for more details. *)
|
(* This file is free software, part of containers. See file "license" for more details. *)
|
||||||
|
|
||||||
(** {1 Basic Bool functions} *)
|
(** {1 Basic Bool functions} *)
|
||||||
|
|
@ -10,6 +9,14 @@ val compare : t -> t -> int
|
||||||
|
|
||||||
val equal : t -> t -> bool
|
val equal : t -> t -> bool
|
||||||
|
|
||||||
|
val to_int : t -> int
|
||||||
|
(** [to_int true = 1], [to_int false = 0].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val of_int : int -> t
|
||||||
|
(** [of_int i] is the same as [i <> 0]
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val negate : t -> t
|
val negate : t -> t
|
||||||
(** Negation on booleans (functional version of [not]).
|
(** Negation on booleans (functional version of [not]).
|
||||||
@deprecated since 1.3, simply use {!not} instead. *)
|
@deprecated since 1.3, simply use {!not} instead. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue