private with Ada.Finalization, Interfaces.C; package Rationals is type Fraction is private; function "+" (Left, Right : in Fraction) return Fraction; function "+" (Left : in Fraction; Right : in Integer) return Fraction; function "+" (Left : in Integer; Right : in Fraction) return Fraction; function "-" (Left, Right : in Fraction) return Fraction; function "-" (Left : in Fraction; Right : in Integer) return Fraction; function "-" (Left : in Integer; Right : in Fraction) return Fraction; function "-" (Right : in Fraction) return Fraction; function "*" (Left, Right : in Fraction) return Fraction; function "*" (Left : in Fraction; Right : in Integer) return Fraction; function "*" (Left : in Integer; Right : in Fraction) return Fraction; function "/" (Left, Right : in Fraction) return Fraction; function "/" (Left : in Fraction; Right : in Integer) return Fraction; function "/" (Left : in Integer; Right : in Fraction) return Fraction; function "/" (Left, Right : in Integer) return Fraction; function "=" (Left, Right : in Fraction) return Boolean; function "=" (Left : in Fraction; Right : in Integer) return Boolean; function "=" (Left : in Integer; Right : in Fraction) return Boolean; function "<=" (Left, Right : in Fraction) return Boolean; function "<=" (Left : in Fraction; Right : in Integer) return Boolean; function "<=" (Left : in Integer; Right : in Fraction) return Boolean; function "<" (Left, Right : in Fraction) return Boolean; function "<" (Left : in Fraction; Right : in Integer) return Boolean; function "<" (Left : in Integer; Right : in Fraction) return Boolean; function ">=" (Left, Right : in Fraction) return Boolean; function ">=" (Left : in Fraction; Right : in Integer) return Boolean; function ">=" (Left : in Integer; Right : in Fraction) return Boolean; function ">" (Left, Right : in Fraction) return Boolean; function ">" (Left : in Fraction; Right : in Integer) return Boolean; function ">" (Left : in Integer; Right : in Fraction) return Boolean; function Numerator (Item : in Fraction) return Long_Integer; function Denominator (Item : in Fraction) return Long_Integer; function Floor (Item : in Fraction) return Long_Integer; function Ceiling (Item : in Fraction) return Long_Integer; function Round (Item : in Fraction) return Long_Integer; private -- Types necessary to bind to GMP type mp_limb_t is new Interfaces.C.unsigned; type mp_ptr is access mp_limb_t; type mpz_t is record mp_alloc, mp_size : Interfaces.C.int; mp_d : mp_ptr; end record; type mpq_t is record mp_num, mp_den : mpz_t; end record; -- The actual type exported by this package, which -- has to be Controlled so it gets deallocated properly type Fraction is new Ada.Finalization.Controlled with record Data : mpq_t; end record; overriding procedure Initialize (This : in out Fraction); overriding procedure Adjust (This : in out Fraction); overriding procedure Finalize (This : in out Fraction); -- Internal type for temporary data to make some Fraction -- functions easier to show as correct type Bignum is new Ada.Finalization.Controlled with record Data : mpz_t; end record; overriding procedure Initialize (This : in out Bignum); overriding procedure Adjust (This : in out Bignum); overriding procedure Finalize (This : in out Bignum); pragma Linker_Options ("-lgmp"); end Rationals;