From 45c752c00a8befa4041b4dcd8243b0563779c573 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 2 Jul 2017 23:39:38 +1000 Subject: Removed MIT licensed Mathpaqs packages in favour of bindings to GMP --- src/rationals.ads | 59 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/rationals.ads') diff --git a/src/rationals.ads b/src/rationals.ads index f12f161..f907633 100644 --- a/src/rationals.ads +++ b/src/rationals.ads @@ -1,8 +1,5 @@ -private with Multi_Precision_Integers; - - -- This source is licensed under Creative Commons CC0 v1.0. -- -- To read the full text, see license.txt in the main directory of this repository @@ -11,6 +8,12 @@ private with Multi_Precision_Integers; -- For a human readable summary, go to https://creativecommons.org/publicdomain/zero/1.0/ +private with + + Ada.Finalization, + Interfaces.C; + + package Rationals is @@ -185,49 +188,63 @@ package Rationals is function Numerator (Item : in Fraction) - return Integer; + return Long_Integer; function Denominator (Item : in Fraction) - return Integer; + return Long_Integer; function Floor (Item : in Fraction) - return Integer; + return Long_Integer; function Ceiling (Item : in Fraction) - return Integer; + return Long_Integer; function Round (Item : in Fraction) - return Integer; + return Long_Integer; +private - function Image - (Item : in Fraction) - return String; + -- Types necessary to bind to GMP + type mp_limb_t is new Interfaces.C.unsigned; + type mp_ptr is access mp_limb_t; - function Value - (Item : in String) - return Fraction; + 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; -private - use Multi_Precision_Integers; + -- 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; - M_Size : constant Basic_Int := 4; + overriding procedure Initialize + (This : in out Fraction); + overriding procedure Adjust + (This : in out Fraction); - type Fraction is record - Num : Multi_Int (M_Size); - Den : Multi_Int (M_Size); - end record; + overriding procedure Finalize + (This : in out Fraction); + + + + + pragma Linker_Options ("-lgmp"); end Rationals; -- cgit