feat: add Q.is_int

This commit is contained in:
Simon Cruanes 2022-01-04 11:11:30 -05:00
parent 2bce3e6dd9
commit 02a9abde3e
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 4 additions and 0 deletions

View file

@ -53,6 +53,9 @@ module type RATIONAL = sig
val is_real : t -> bool
(** A proper real, not nan/infinity *)
val is_int : t -> bool
(** Is this a proper integer? *)
val pp_approx : int -> Format.formatter -> t -> unit
(** Pretty print rational with given amount of precision
(for example as a floating point number) *)

View file

@ -18,6 +18,7 @@ module Rational
let infinity = Q.inf
let minus_infinity = Q.minus_inf
let is_real = Q.is_real
let is_int q = is_real q && Z.(equal (denum q) one)
let pp_approx n out q = Format.fprintf out "%*.1f" n (Q.to_float q)
end