mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
make CCInt64 compatible with Int64 (breaking!) (closes #192)
conversion functions are total, even when the bit widths do not correspond. Returning options does not make sense in this context.
This commit is contained in:
parent
580dc58979
commit
62ba3c00af
2 changed files with 26 additions and 34 deletions
|
|
@ -35,21 +35,11 @@ let hash x = Pervasives.abs (to_int x)
|
||||||
(** {2 Conversion} *)
|
(** {2 Conversion} *)
|
||||||
|
|
||||||
let of_int_exn = of_int
|
let of_int_exn = of_int
|
||||||
|
|
||||||
let of_int x = try Some (of_int_exn x) with Failure _ -> None
|
|
||||||
|
|
||||||
let of_nativeint_exn = of_nativeint
|
let of_nativeint_exn = of_nativeint
|
||||||
|
|
||||||
let of_nativeint x = try Some (of_nativeint_exn x) with Failure _ -> None
|
|
||||||
|
|
||||||
let of_int32_exn = of_int32
|
let of_int32_exn = of_int32
|
||||||
|
|
||||||
let of_int32 x = try Some (of_int32_exn x) with Failure _ -> None
|
|
||||||
|
|
||||||
let of_float_exn = of_float
|
let of_float_exn = of_float
|
||||||
|
|
||||||
let of_float x = try Some (of_float_exn x) with Failure _ -> None
|
|
||||||
|
|
||||||
let of_string_exn = of_string
|
let of_string_exn = of_string
|
||||||
|
|
||||||
let of_string x = try Some (of_string_exn x) with Failure _ -> None
|
let of_string x = try Some (of_string_exn x) with Failure _ -> None
|
||||||
|
let of_string_opt = of_string
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
@since 0.13 *)
|
@since 0.13 *)
|
||||||
|
|
||||||
type t = int64
|
include module type of struct include Int64 end
|
||||||
|
|
||||||
val (+) : t -> t -> t
|
val (+) : t -> t -> t
|
||||||
(** Addition. *)
|
(** Addition. *)
|
||||||
|
|
@ -89,14 +89,13 @@ val to_int : t -> int
|
||||||
is taken modulo 2{^31}, i.e. the top 33 bits are lost
|
is taken modulo 2{^31}, i.e. the top 33 bits are lost
|
||||||
during the conversion. *)
|
during the conversion. *)
|
||||||
|
|
||||||
val of_int : int -> t option
|
val of_int : int -> t
|
||||||
(** Safe version of {!of_int_exn}. *)
|
(** Alias to {!Int64.of_int}
|
||||||
|
NOTE: used to return an option, but the function actually never fails *)
|
||||||
|
|
||||||
val of_int_exn : int -> t
|
val of_int_exn : int -> t
|
||||||
(** Alias to {!Int64.of_int}.
|
(** Alias to {!Int64.of_int}.
|
||||||
Convert the given integer (type [int]) to a 64-bit integer
|
@deprecated since NEXT_RELEASE *)
|
||||||
(type [int64]).
|
|
||||||
@raise Failure in case of failure. *)
|
|
||||||
|
|
||||||
val to_int32 : t -> int32
|
val to_int32 : t -> int32
|
||||||
(** Convert the given 64-bit integer (type [int64]) to a
|
(** Convert the given 64-bit integer (type [int64]) to a
|
||||||
|
|
@ -104,14 +103,13 @@ val to_int32 : t -> int32
|
||||||
is taken modulo 2{^32}, i.e. the top 32 bits are lost
|
is taken modulo 2{^32}, i.e. the top 32 bits are lost
|
||||||
during the conversion. *)
|
during the conversion. *)
|
||||||
|
|
||||||
val of_int32 : int32 -> t option
|
val of_int32 : int32 -> t
|
||||||
(** Safe version of {!of_int32_exn}. *)
|
(** Alias to {!Int64.of_int32}
|
||||||
|
NOTE: use to return an option, but the function actually never fails. *)
|
||||||
|
|
||||||
val of_int32_exn : int32 -> t
|
val of_int32_exn : int32 -> t
|
||||||
(** Alias to {!Int64.of_int32}
|
(** Alias to {!Int64.of_int32}
|
||||||
Convert the given 32-bit integer (type [int32])
|
@deprecated since NEXT_RELEASE *)
|
||||||
to a 64-bit integer (type [int64]).
|
|
||||||
@raise Failure in case of failure. *)
|
|
||||||
|
|
||||||
val to_nativeint : t -> nativeint
|
val to_nativeint : t -> nativeint
|
||||||
(** Convert the given 64-bit integer (type [int64]) to a
|
(** Convert the given 64-bit integer (type [int64]) to a
|
||||||
|
|
@ -119,28 +117,28 @@ val to_nativeint : t -> nativeint
|
||||||
is taken modulo 2{^32}. On 64-bit platforms,
|
is taken modulo 2{^32}. On 64-bit platforms,
|
||||||
the conversion is exact. *)
|
the conversion is exact. *)
|
||||||
|
|
||||||
val of_nativeint : nativeint -> t option
|
val of_nativeint : nativeint -> t
|
||||||
(** Safe version of {!of_nativeint_exn}. *)
|
(** Alias to {!Int64.of_nativeint}.
|
||||||
|
NOTE: use to return an option, but the function actually never fails. *)
|
||||||
|
|
||||||
val of_nativeint_exn : nativeint -> t
|
val of_nativeint_exn : nativeint -> t
|
||||||
(** Alias to {!Int64.of_nativeint}.
|
(** Alias to {!Int64.of_nativeint}
|
||||||
Convert the given native integer (type [nativeint])
|
@deprecated since NEXT_RELEASE *)
|
||||||
to a 64-bit integer (type [int64]).
|
|
||||||
@raise Failure in case of failure. *)
|
|
||||||
|
|
||||||
val to_float : t -> float
|
val to_float : t -> float
|
||||||
(** Convert the given 64-bit integer to a floating-point number. *)
|
(** Convert the given 64-bit integer to a floating-point number. *)
|
||||||
|
|
||||||
val of_float : float -> t option
|
val of_float : float -> t
|
||||||
(** Safe version of {!of_float_exn}. *)
|
|
||||||
|
|
||||||
val of_float_exn : float -> t
|
|
||||||
(** Alias to {!Int64.of_float}.
|
(** Alias to {!Int64.of_float}.
|
||||||
Convert the given floating-point number to a 64-bit integer,
|
Convert the given floating-point number to a 64-bit integer,
|
||||||
discarding the fractional part (truncate towards 0).
|
discarding the fractional part (truncate towards 0).
|
||||||
The result of the conversion is undefined if, after truncation,
|
The result of the conversion is undefined if, after truncation,
|
||||||
the number is outside the range \[{!CCInt64.min_int}, {!CCInt64.max_int}\].
|
the number is outside the range \[{!CCInt64.min_int}, {!CCInt64.max_int}\].
|
||||||
@raise Failure in case of failure. *)
|
NOTE: used to return an option, but the function never fails *)
|
||||||
|
|
||||||
|
val of_float_exn : float -> t
|
||||||
|
(** Alias to {!Int64.of_float}.
|
||||||
|
@deprecated since NEXT_RELEASE *)
|
||||||
|
|
||||||
val to_string : t -> string
|
val to_string : t -> string
|
||||||
(** Return the string representation of its argument, in decimal. *)
|
(** Return the string representation of its argument, in decimal. *)
|
||||||
|
|
@ -148,6 +146,10 @@ val to_string : t -> string
|
||||||
val of_string : string -> t option
|
val of_string : string -> t option
|
||||||
(** Safe version of {!of_string_exn}. *)
|
(** Safe version of {!of_string_exn}. *)
|
||||||
|
|
||||||
|
val of_string_opt : string -> t option
|
||||||
|
(** Alias to {!of_string}
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val of_string_exn : string -> t
|
val of_string_exn : string -> t
|
||||||
(** Alias to {!Int64.of_string}.
|
(** Alias to {!Int64.of_string}.
|
||||||
Convert the given string to a 64-bit integer.
|
Convert the given string to a 64-bit integer.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue