annotate gcc/ada/libgnat/s-bignum.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . B I G N U M S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2012-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package provides arbitrary precision signed integer arithmetic for
kono
parents:
diff changeset
33 -- use in computing intermediate values in expressions for the case where
kono
parents:
diff changeset
34 -- pragma Overflow_Check (Eliminated) is in effect.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 with Interfaces;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 package System.Bignums is
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 pragma Assert (Long_Long_Integer'Size = 64);
kono
parents:
diff changeset
41 -- This package assumes that Long_Long_Integer size is 64 bit (i.e. that it
kono
parents:
diff changeset
42 -- has a range of -2**63 to 2**63-1). The front end ensures that the mode
kono
parents:
diff changeset
43 -- ELIMINATED is not allowed for overflow checking if this is not the case.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 subtype Length is Natural range 0 .. 2 ** 23 - 1;
kono
parents:
diff changeset
46 -- Represent number of words in Digit_Vector
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 Base : constant := 2 ** 32;
kono
parents:
diff changeset
49 -- Digit vectors use this base
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 subtype SD is Interfaces.Unsigned_32;
kono
parents:
diff changeset
52 -- Single length digit
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 type Digit_Vector is array (Length range <>) of SD;
kono
parents:
diff changeset
55 -- Represent digits of a number (most significant digit first)
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 type Bignum_Data (Len : Length) is record
kono
parents:
diff changeset
58 Neg : Boolean;
kono
parents:
diff changeset
59 -- Set if value is negative, never set for zero
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 D : Digit_Vector (1 .. Len);
kono
parents:
diff changeset
62 -- Digits of number, most significant first, represented in base
kono
parents:
diff changeset
63 -- 2**Base. No leading zeroes are stored, and the value of zero is
kono
parents:
diff changeset
64 -- represented using an empty vector for D.
kono
parents:
diff changeset
65 end record;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 for Bignum_Data use record
kono
parents:
diff changeset
68 Len at 0 range 0 .. 23;
kono
parents:
diff changeset
69 Neg at 3 range 0 .. 7;
kono
parents:
diff changeset
70 end record;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 type Bignum is access all Bignum_Data;
kono
parents:
diff changeset
73 -- This is the type that is used externally. Possibly this could be a
kono
parents:
diff changeset
74 -- private type, but we leave the structure exposed for now. For one
kono
parents:
diff changeset
75 -- thing it helps with debugging. Note that this package never shares
kono
parents:
diff changeset
76 -- an allocated Bignum value, so for example for X + 0, a copy of X is
kono
parents:
diff changeset
77 -- returned, not X itself.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 -- Note: none of the subprograms in this package modify the Bignum_Data
kono
parents:
diff changeset
80 -- records referenced by Bignum arguments of mode IN.
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Big_Add (X, Y : Bignum) return Bignum; -- "+"
kono
parents:
diff changeset
83 function Big_Sub (X, Y : Bignum) return Bignum; -- "-"
kono
parents:
diff changeset
84 function Big_Mul (X, Y : Bignum) return Bignum; -- "*"
kono
parents:
diff changeset
85 function Big_Div (X, Y : Bignum) return Bignum; -- "/"
kono
parents:
diff changeset
86 function Big_Exp (X, Y : Bignum) return Bignum; -- "**"
kono
parents:
diff changeset
87 function Big_Mod (X, Y : Bignum) return Bignum; -- "mod"
kono
parents:
diff changeset
88 function Big_Rem (X, Y : Bignum) return Bignum; -- "rem"
kono
parents:
diff changeset
89 function Big_Neg (X : Bignum) return Bignum; -- "-"
kono
parents:
diff changeset
90 function Big_Abs (X : Bignum) return Bignum; -- "abs"
kono
parents:
diff changeset
91 -- Perform indicated arithmetic operation on bignum values. No exception
kono
parents:
diff changeset
92 -- raised except for Div/Mod/Rem by 0 which raises Constraint_Error with
kono
parents:
diff changeset
93 -- an appropriate message.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 function Big_EQ (X, Y : Bignum) return Boolean; -- "="
kono
parents:
diff changeset
96 function Big_NE (X, Y : Bignum) return Boolean; -- "/="
kono
parents:
diff changeset
97 function Big_GE (X, Y : Bignum) return Boolean; -- ">="
kono
parents:
diff changeset
98 function Big_LE (X, Y : Bignum) return Boolean; -- "<="
kono
parents:
diff changeset
99 function Big_GT (X, Y : Bignum) return Boolean; -- ">"
kono
parents:
diff changeset
100 function Big_LT (X, Y : Bignum) return Boolean; -- "<"
kono
parents:
diff changeset
101 -- Perform indicated comparison on bignums, returning result as Boolean.
kono
parents:
diff changeset
102 -- No exception raised for any input arguments.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 function Bignum_In_LLI_Range (X : Bignum) return Boolean;
kono
parents:
diff changeset
105 -- Returns True if the Bignum value is in the range of Long_Long_Integer,
kono
parents:
diff changeset
106 -- so that a call to From_Bignum is guaranteed not to raise an exception.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 function To_Bignum (X : Long_Long_Integer) return Bignum;
kono
parents:
diff changeset
109 -- Convert Long_Long_Integer to Bignum. No exception can be raised for any
kono
parents:
diff changeset
110 -- input argument.
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 function From_Bignum (X : Bignum) return Long_Long_Integer;
kono
parents:
diff changeset
113 -- Convert Bignum to Long_Long_Integer. Constraint_Error raised with
kono
parents:
diff changeset
114 -- appropriate message if value is out of range of Long_Long_Integer.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 end System.Bignums;