Commit 04b633a8 by Robert Dewar Committed by Arnaud Charlet

s-arit64.adb: (Le3): New function, used by Scaled_Divide

2004-10-26  Robert Dewar  <dewar@gnat.com>

	* s-arit64.adb: (Le3): New function, used by Scaled_Divide
	(Sub3): New procedure, used by Scaled_Divide
	(Scaled_Divide): Substantial rewrite, avoid duplicated code, and also
	correct more than one instance of failure to propagate carries
	correctly.
	(Double_Divide): Handle overflow case of largest negative number
	divided by minus one.

	* s-arit64.ads (Double_Divide): Document that overflow can occur in
	the case of a quotient value out of range.
	Fix comments.

From-SVN: r89663
parent 1ae44ba2
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1994,1995,1996 Free Software Foundation, Inc. -- -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -52,7 +52,7 @@ pragma Pure (Arith_64); ...@@ -52,7 +52,7 @@ pragma Pure (Arith_64);
function Multiply_With_Ovflo_Check (X, Y : Int64) return Int64; function Multiply_With_Ovflo_Check (X, Y : Int64) return Int64;
-- Raises Constraint_Error if product of operands overflows 64 -- Raises Constraint_Error if product of operands overflows 64
-- bits, otherwise returns the 64-bit signed integer difference. -- bits, otherwise returns the 64-bit signed integer product.
procedure Scaled_Divide procedure Scaled_Divide
(X, Y, Z : Int64; (X, Y, Z : Int64;
...@@ -71,12 +71,11 @@ pragma Pure (Arith_64); ...@@ -71,12 +71,11 @@ pragma Pure (Arith_64);
Q, R : out Int64; Q, R : out Int64;
Round : Boolean); Round : Boolean);
-- Performs the division X / (Y * Z), storing the quotient in Q and -- Performs the division X / (Y * Z), storing the quotient in Q and
-- the remainder in R. Constraint_Error is raised if Y or Z is zero. -- the remainder in R. Constraint_Error is raised if Y or Z is zero,
-- Round indicates if the result should be rounded. If Round is False, -- or if the quotient does not fit in 64-bits. Round indicates if the
-- then Q, R are the normal quotient and remainder from a truncating -- result should be rounded. If Round is False, then Q, R are the normal
-- division. If Round is True, then Q is the rounded quotient. The -- quotient and remainder from a truncating division. If Round is True,
-- remainder R is not affected by the setting of the Round flag. The -- then Q is the rounded quotient. The remainder R is not affected by the
-- result is known to be in range except for the noted possibility of -- setting of the Round flag.
-- Y or Z being zero, so no other overflow checks are required.
end System.Arith_64; end System.Arith_64;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment