Debian Codegraph @

gcc/ada/libgnat/s-exponu.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . E X P O N U --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-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 function implements unsigned integer exponentiation
33
34 -- Preconditions in this unit are meant for analysis only, not for run-time
35 -- checking, so that the expected exceptions are raised. This is enforced
36 -- by setting the corresponding assertion policy to Ignore. Postconditions
37 -- and contract cases should not be executed at runtime as well, in order
38 -- not to slow down the execution of these functions.
39
40 pragma Assertion_Policy (Pre => Ignore,
41 Post => Ignore,
42 Contract_Cases => Ignore,
43 Ghost => Ignore);
44
45 generic
46
47 type Int is mod <>;
48
49 function System.Exponu (Left : Int; Right : Natural) return Int
50 with
51 SPARK_Mode,
52 Post => System.Exponu'Result = Left ** Right;
53 -- Calculate ``Left`` ** ``Right``. If ``Left`` is 0 then 0 is returned
54 -- and if ``Right`` is 0 then 1 is returned. In all other cases the result
55 -- is set to 1 and then computed in a loop as follows:
56 -- If ``Right`` is a multiple of 2 then multiply the result with ``Left``.
57 -- Divide ``Right`` by 2.
58 -- If ``Right is 0, return.
59 -- Multiply ``Left`` with itself.