aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-reatim.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2015-10-23 14:52:53 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2015-10-23 14:52:53 +0200
commita1c09064183ef120c05fb6ded552029ca79dbff9 (patch)
tree0f22cea6c8d25e3e46429b296274a9f726a2b8ca /gcc/ada/a-reatim.adb
parent241fac51c3e6a4745d28b36121702325212c3af6 (diff)
downloadgcc-a1c09064183ef120c05fb6ded552029ca79dbff9.zip
gcc-a1c09064183ef120c05fb6ded552029ca79dbff9.tar.gz
gcc-a1c09064183ef120c05fb6ded552029ca79dbff9.tar.bz2
[multiple changes]
2015-10-23 Gary Dismukes <dismukes@adacore.com> * exp_ch6.adb: Minor reformatting. 2015-10-23 Ed Schonberg <schonberg@adacore.com> * sem_ch12.adb (Check_Formal_Packages): A formal package whose actual part is (others => <>) os identical to a formal package with an actual part written as (<>). 2015-10-23 Arnaud Charlet <charlet@adacore.com> * a-reatim.adb ("/"): For Time_Span division convert the operands to integers and then use integer division, which conforms to the rounding required by Ada RM. From-SVN: r229250
Diffstat (limited to 'gcc/ada/a-reatim.adb')
-rw-r--r--gcc/ada/a-reatim.adb15
1 files changed, 14 insertions, 1 deletions
diff --git a/gcc/ada/a-reatim.adb b/gcc/ada/a-reatim.adb
index 4bac97b..83ff25b 100644
--- a/gcc/ada/a-reatim.adb
+++ b/gcc/ada/a-reatim.adb
@@ -31,6 +31,7 @@
------------------------------------------------------------------------------
with System.Tasking;
+with Unchecked_Conversion;
package body Ada.Real_Time with
SPARK_Mode => Off
@@ -117,8 +118,20 @@ is
function "/" (Left, Right : Time_Span) return Integer is
pragma Unsuppress (Overflow_Check);
pragma Unsuppress (Division_Check);
+
+ -- RM D.8 (27) specifies the effects of operators on Time_Span, and
+ -- rounding of the division operator in particular, to be the same as
+ -- effects on integer types. To get the correct rounding we first
+ -- convert Time_Span to its root type Duration, which is represented as
+ -- an 64-bit signed integer, and then use integer division.
+
+ type Duration_Rep is range -(2 ** 63) .. +((2 ** 63 - 1));
+
+ function To_Integer is
+ new Unchecked_Conversion (Duration, Duration_Rep);
begin
- return Integer (Duration (Left) / Duration (Right));
+ return Integer
+ (To_Integer (Duration (Left)) / To_Integer (Duration (Right)));
end "/";
function "/" (Left : Time_Span; Right : Integer) return Time_Span is