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:
Simon Cruanes 2018-02-17 10:25:57 -06:00
parent 580dc58979
commit 62ba3c00af
2 changed files with 26 additions and 34 deletions

View file

@ -35,21 +35,11 @@ let hash x = Pervasives.abs (to_int x)
(** {2 Conversion} *)
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 x = try Some (of_nativeint_exn x) with Failure _ -> None
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 x = try Some (of_float_exn x) with Failure _ -> None
let of_string_exn = of_string
let of_string x = try Some (of_string_exn x) with Failure _ -> None
let of_string_opt = of_string

View file

@ -6,7 +6,7 @@
@since 0.13 *)
type t = int64
include module type of struct include Int64 end
val (+) : t -> t -> t
(** Addition. *)
@ -89,14 +89,13 @@ val to_int : t -> int
is taken modulo 2{^31}, i.e. the top 33 bits are lost
during the conversion. *)
val of_int : int -> t option
(** Safe version of {!of_int_exn}. *)
val of_int : int -> t
(** Alias to {!Int64.of_int}
NOTE: used to return an option, but the function actually never fails *)
val of_int_exn : int -> t
(** Alias to {!Int64.of_int}.
Convert the given integer (type [int]) to a 64-bit integer
(type [int64]).
@raise Failure in case of failure. *)
@deprecated since NEXT_RELEASE *)
val to_int32 : t -> int32
(** 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
during the conversion. *)
val of_int32 : int32 -> t option
(** Safe version of {!of_int32_exn}. *)
val of_int32 : int32 -> t
(** Alias to {!Int64.of_int32}
NOTE: use to return an option, but the function actually never fails. *)
val of_int32_exn : int32 -> t
(** Alias to {!Int64.of_int32}
Convert the given 32-bit integer (type [int32])
to a 64-bit integer (type [int64]).
@raise Failure in case of failure. *)
@deprecated since NEXT_RELEASE *)
val to_nativeint : t -> nativeint
(** 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,
the conversion is exact. *)
val of_nativeint : nativeint -> t option
(** Safe version of {!of_nativeint_exn}. *)
val of_nativeint : nativeint -> t
(** Alias to {!Int64.of_nativeint}.
NOTE: use to return an option, but the function actually never fails. *)
val of_nativeint_exn : nativeint -> t
(** Alias to {!Int64.of_nativeint}.
Convert the given native integer (type [nativeint])
to a 64-bit integer (type [int64]).
@raise Failure in case of failure. *)
(** Alias to {!Int64.of_nativeint}
@deprecated since NEXT_RELEASE *)
val to_float : t -> float
(** Convert the given 64-bit integer to a floating-point number. *)
val of_float : float -> t option
(** Safe version of {!of_float_exn}. *)
val of_float_exn : float -> t
val of_float : float -> t
(** Alias to {!Int64.of_float}.
Convert the given floating-point number to a 64-bit integer,
discarding the fractional part (truncate towards 0).
The result of the conversion is undefined if, after truncation,
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
(** Return the string representation of its argument, in decimal. *)
@ -148,10 +146,14 @@ val to_string : t -> string
val of_string : string -> t option
(** 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
(** Alias to {!Int64.of_string}.
Convert the given string to a 64-bit integer.
The string is read in decimal (by default, or if the string
The string is read in decimal (by default, or if the string
begins with [0u]) or in hexadecimal, octal or binary if the
string begins with [0x], [0o] or [0b] respectively.