1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- S Y S T E M . A R I T H _ D O U B L E -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1992-2020, 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 software routines for doing arithmetic on "double" 33-- signed integer values in cases where either overflow checking is required, 34-- or intermediate results are longer than the result type. 35 36generic 37 38 type Double_Int is range <>; 39 40 type Double_Uns is mod <>; 41 42 type Single_Uns is mod <>; 43 44 with function Shift_Left (A : Double_Uns; B : Natural) return Double_Uns 45 is <>; 46 47 with function Shift_Right (A : Double_Uns; B : Natural) return Double_Uns 48 is <>; 49 50 with function Shift_Left (A : Single_Uns; B : Natural) return Single_Uns 51 is <>; 52 53package System.Arith_Double is 54 pragma Pure; 55 56 function Add_With_Ovflo_Check (X, Y : Double_Int) return Double_Int; 57 -- Raises Constraint_Error if sum of operands overflows Double_Int, 58 -- otherwise returns the signed integer sum. 59 60 function Subtract_With_Ovflo_Check (X, Y : Double_Int) return Double_Int; 61 -- Raises Constraint_Error if difference of operands overflows Double_Int, 62 -- otherwise returns the signed integer difference. 63 64 function Multiply_With_Ovflo_Check (X, Y : Double_Int) return Double_Int; 65 pragma Convention (C, Multiply_With_Ovflo_Check); 66 -- Raises Constraint_Error if product of operands overflows Double_Int, 67 -- otherwise returns the signed integer product. Gigi may also call this 68 -- routine directly. 69 70 procedure Scaled_Divide 71 (X, Y, Z : Double_Int; 72 Q, R : out Double_Int; 73 Round : Boolean); 74 -- Performs the division of (X * Y) / Z, storing the quotient in Q 75 -- and the remainder in R. Constraint_Error is raised if Z is zero, 76 -- or if the quotient does not fit in Double_Int. Round indicates if 77 -- the result should be rounded. If Round is False, then Q, R are 78 -- the normal quotient and remainder from a truncating division. 79 -- If Round is True, then Q is the rounded quotient. The remainder 80 -- R is not affected by the setting of the Round flag. 81 82 procedure Double_Divide 83 (X, Y, Z : Double_Int; 84 Q, R : out Double_Int; 85 Round : Boolean); 86 -- Performs the division X / (Y * Z), storing the quotient in Q and 87 -- the remainder in R. Constraint_Error is raised if Y or Z is zero, 88 -- or if the quotient does not fit in Double_Int. Round indicates if the 89 -- result should be rounded. If Round is False, then Q, R are the normal 90 -- quotient and remainder from a truncating division. If Round is True, 91 -- then Q is the rounded quotient. The remainder R is not affected by the 92 -- setting of the Round flag. 93 94end System.Arith_Double; 95