| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . B I G N U M S -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2012-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 17 |
-- -- |
| 18 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 19 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 20 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 21 |
-- -- |
| 22 |
-- You should have received a copy of the GNU General Public License and -- |
| 23 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 24 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 25 |
-- <http://www.gnu.org/licenses/>. -- |
| 26 |
-- -- |
| 27 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- This package provides arbitrary precision signed integer arithmetic for |
| 33 |
-- use in computing intermediate values in expressions for the case where |
| 34 |
-- pragma Overflow_Check (Eliminated) is in effect. |
| 35 |
|
| 36 |
-- Note that we cannot use a straight instantiation of System.Generic_Bignums |
| 37 |
-- because the rtsfind mechanism is not ready to handle instantiations. |
| 38 |
|
| 39 |
with System.Shared_Bignums; |
| 40 |
|
| 41 |
package System.Bignums is |
| 42 |
pragma Preelaborate; |
| 43 |
|
| 44 |
subtype Bignum is System.Shared_Bignums.Bignum; |
| 45 |
|
| 46 |
function Big_Add (X, Y : Bignum) return Bignum; -- "+" |
| 47 |
function Big_Sub (X, Y : Bignum) return Bignum; -- "-" |
| 48 |
function Big_Mul (X, Y : Bignum) return Bignum; -- "*" |
| 49 |
function Big_Div (X, Y : Bignum) return Bignum; -- "/" |
| 50 |
function Big_Exp (X, Y : Bignum) return Bignum; -- "**" |
| 51 |
function Big_Mod (X, Y : Bignum) return Bignum; -- "mod" |
| 52 |
function Big_Rem (X, Y : Bignum) return Bignum; -- "rem" |
| 53 |
function Big_Neg (X : Bignum) return Bignum; -- "-" |
| 54 |
function Big_Abs (X : Bignum) return Bignum; -- "abs" |
| 55 |
-- Perform indicated arithmetic operation on bignum values. No exception |
| 56 |
-- raised except for Div/Mod/Rem by 0 which raises Constraint_Error with |
| 57 |
-- an appropriate message. |
| 58 |
|
| 59 |
function Big_EQ (X, Y : Bignum) return Boolean; -- "=" |
| 60 |
function Big_NE (X, Y : Bignum) return Boolean; -- "/=" |
| 61 |
function Big_GE (X, Y : Bignum) return Boolean; -- ">=" |
| 62 |
function Big_LE (X, Y : Bignum) return Boolean; -- "<=" |
| 63 |
function Big_GT (X, Y : Bignum) return Boolean; -- ">" |
| 64 |
function Big_LT (X, Y : Bignum) return Boolean; -- "<" |
| 65 |
-- Perform indicated comparison on bignums, returning result as Boolean. |
| 66 |
-- No exception raised for any input arguments. |
| 67 |
|
| 68 |
function Bignum_In_LLI_Range (X : Bignum) return Boolean; |
| 69 |
-- Returns True if the Bignum value is in the range of Long_Long_Integer, |
| 70 |
-- so that a call to From_Bignum is guaranteed not to raise an exception. |
| 71 |
|
| 72 |
function To_Bignum (X : Long_Long_Integer) return Bignum; |
| 73 |
-- Convert Long_Long_Integer to Bignum. No exception can be raised for any |
| 74 |
-- input argument. |
| 75 |
|
| 76 |
function From_Bignum (X : Bignum) return Long_Long_Integer; |
| 77 |
-- Convert Bignum to Long_Long_Integer. Constraint_Error raised with |
| 78 |
-- appropriate message if value is out of range of Long_Long_Integer. |
| 79 |
|
| 80 |
private |
| 81 |
|
| 82 |
pragma Inline (Big_Add); |
| 83 |
pragma Inline (Big_Sub); |
| 84 |
pragma Inline (Big_Mul); |
| 85 |
pragma Inline (Big_Div); |
| 86 |
pragma Inline (Big_Exp); |
| 87 |
pragma Inline (Big_Mod); |
| 88 |
pragma Inline (Big_Rem); |
| 89 |
pragma Inline (Big_Neg); |
| 90 |
pragma Inline (Big_Abs); |
| 91 |
pragma Inline (Big_EQ); |
| 92 |
pragma Inline (Big_NE); |
| 93 |
pragma Inline (Big_GE); |
| 94 |
pragma Inline (Big_LE); |
| 95 |
pragma Inline (Big_GT); |
| 96 |
pragma Inline (Big_LT); |
| 97 |
pragma Inline (Bignum_In_LLI_Range); |
| 98 |
pragma Inline (To_Bignum); |
| 99 |
pragma Inline (From_Bignum); |
| 100 |
|
| 101 |
end System.Bignums; |