mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 03:05:31 -05:00
arith: more functions in Int
This commit is contained in:
parent
417f4cf8ec
commit
7ea4c4fb4a
3 changed files with 26 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ module type NUM = sig
|
||||||
val one : t
|
val one : t
|
||||||
val minus_one : t
|
val minus_one : t
|
||||||
|
|
||||||
|
val abs : t -> t
|
||||||
val sign : t -> int
|
val sign : t -> int
|
||||||
|
|
||||||
val of_int : int -> t
|
val of_int : int -> t
|
||||||
|
|
@ -35,6 +36,7 @@ module type INT = sig
|
||||||
include NUM
|
include NUM
|
||||||
|
|
||||||
val succ : t -> t
|
val succ : t -> t
|
||||||
|
val pred : t -> t
|
||||||
val gcd : t -> t -> t
|
val gcd : t -> t -> t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -72,3 +74,19 @@ module type RATIONAL = sig
|
||||||
(** Pretty print rational with given amount of precision
|
(** Pretty print rational with given amount of precision
|
||||||
(for example as a floating point number) *)
|
(for example as a floating point number) *)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module type INT_FULL = sig
|
||||||
|
include INT
|
||||||
|
|
||||||
|
val sqrt : t -> t
|
||||||
|
|
||||||
|
val divexact : t -> t -> t
|
||||||
|
|
||||||
|
val (/) : t -> t -> t
|
||||||
|
|
||||||
|
val rem : t -> t -> t
|
||||||
|
|
||||||
|
val probab_prime : t -> bool
|
||||||
|
|
||||||
|
val pow : t -> int -> t
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
|
|
||||||
|
|
||||||
module Int : Sidekick_arith.INT with type t = Z.t = struct
|
module Int : Sidekick_arith.INT_FULL with type t = Z.t = struct
|
||||||
include Z
|
include Z
|
||||||
include Z.Compare
|
include Z.Compare
|
||||||
let pp = pp_print
|
let pp = pp_print
|
||||||
|
let divexact = divexact
|
||||||
|
let (/) = div
|
||||||
|
let probab_prime x = match probab_prime x 10 with
|
||||||
|
| 0 -> false
|
||||||
|
| 1 | 2 -> true
|
||||||
|
| _ -> assert false
|
||||||
end
|
end
|
||||||
|
|
||||||
module Rational
|
module Rational
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
module Int : Sidekick_arith.INT with type t = Z.t
|
module Int : Sidekick_arith.INT_FULL with type t = Z.t
|
||||||
|
|
||||||
module Rational : Sidekick_arith.RATIONAL with type t = Q.t and type bigint = Z.t
|
module Rational : Sidekick_arith.RATIONAL with type t = Q.t and type bigint = Z.t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue