summaryrefslogtreecommitdiff
path: root/src/rationals.ads
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-07-02 23:39:38 +1000
committerJed Barber <jjbarber@y7mail.com>2017-07-02 23:39:38 +1000
commit45c752c00a8befa4041b4dcd8243b0563779c573 (patch)
tree4d68902cfde9010b43e6a331cd307dd00fc28b7f /src/rationals.ads
parentbf374b8b8970bbb17ec360b33e46c859010830a1 (diff)
Removed MIT licensed Mathpaqs packages in favour of bindings to GMP
Diffstat (limited to 'src/rationals.ads')
-rw-r--r--src/rationals.ads59
1 files changed, 38 insertions, 21 deletions
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;