PR target/81369
[official-gcc.git] / gcc / ada / a-ngelfu.ads
blob767708d52095616cf0b6ec585be26ff1e6ee11cc
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- ADA.NUMERICS.GENERIC_ELEMENTARY_FUNCTIONS --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2012-2016, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the Post aspects that have been added to the spec. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
21 -- --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
36 generic
37 type Float_Type is digits <>;
39 package Ada.Numerics.Generic_Elementary_Functions with
40 SPARK_Mode => On
42 pragma Pure;
44 function Sqrt (X : Float_Type'Base) return Float_Type'Base with
45 Post => Sqrt'Result >= 0.0
46 and then (if X = 0.0 then Sqrt'Result = 0.0)
47 and then (if X = 1.0 then Sqrt'Result = 1.0)
49 -- Finally if X is positive, the result of Sqrt is positive (because
50 -- the sqrt of numbers greater than 1 is greater than or equal to 1,
51 -- and the sqrt of numbers less than 1 is greater than the argument).
53 -- This property is useful in particular for static analysis. The
54 -- property that X is positive is not expressed as (X > 0.0), as
55 -- the value X may be held in registers that have larger range and
56 -- precision on some architecture (for example, on x86 using x387
57 -- FPU, as opposed to SSE2). So, it might be possible for X to be
58 -- 2.0**(-5000) or so, which could cause the number to compare as
59 -- greater than 0, but Sqrt would still return a zero result.
61 -- Note: we use the comparison with Succ (0.0) here because this is
62 -- more amenable to CodePeer analysis than the use of 'Machine.
64 and then (if X >= Float_Type'Succ (0.0) then Sqrt'Result > 0.0);
66 function Log (X : Float_Type'Base) return Float_Type'Base with
67 Post => (if X = 1.0 then Log'Result = 0.0);
69 function Log (X, Base : Float_Type'Base) return Float_Type'Base with
70 Post => (if X = 1.0 then Log'Result = 0.0);
72 function Exp (X : Float_Type'Base) return Float_Type'Base with
73 Post => (if X = 0.0 then Exp'Result = 1.0);
75 function "**" (Left, Right : Float_Type'Base) return Float_Type'Base with
76 Post => "**"'Result >= 0.0
77 and then (if Right = 0.0 then "**"'Result = 1.0)
78 and then (if Right = 1.0 then "**"'Result = Left)
79 and then (if Left = 1.0 then "**"'Result = 1.0)
80 and then (if Left = 0.0 then "**"'Result = 0.0);
82 function Sin (X : Float_Type'Base) return Float_Type'Base with
83 Post => Sin'Result in -1.0 .. 1.0
84 and then (if X = 0.0 then Sin'Result = 0.0);
86 function Sin (X, Cycle : Float_Type'Base) return Float_Type'Base with
87 Post => Sin'Result in -1.0 .. 1.0
88 and then (if X = 0.0 then Sin'Result = 0.0);
90 function Cos (X : Float_Type'Base) return Float_Type'Base with
91 Post => Cos'Result in -1.0 .. 1.0
92 and then (if X = 0.0 then Cos'Result = 1.0);
94 function Cos (X, Cycle : Float_Type'Base) return Float_Type'Base with
95 Post => Cos'Result in -1.0 .. 1.0
96 and then (if X = 0.0 then Cos'Result = 1.0);
98 function Tan (X : Float_Type'Base) return Float_Type'Base with
99 Post => (if X = 0.0 then Tan'Result = 0.0);
101 function Tan (X, Cycle : Float_Type'Base) return Float_Type'Base with
102 Post => (if X = 0.0 then Tan'Result = 0.0);
104 function Cot (X : Float_Type'Base) return Float_Type'Base;
106 function Cot (X, Cycle : Float_Type'Base) return Float_Type'Base;
108 function Arcsin (X : Float_Type'Base) return Float_Type'Base with
109 Post => (if X = 0.0 then Arcsin'Result = 0.0);
111 function Arcsin (X, Cycle : Float_Type'Base) return Float_Type'Base with
112 Post => (if X = 0.0 then Arcsin'Result = 0.0);
114 function Arccos (X : Float_Type'Base) return Float_Type'Base with
115 Post => (if X = 1.0 then Arccos'Result = 0.0);
117 function Arccos (X, Cycle : Float_Type'Base) return Float_Type'Base with
118 Post => (if X = 1.0 then Arccos'Result = 0.0);
120 function Arctan
121 (Y : Float_Type'Base;
122 X : Float_Type'Base := 1.0) return Float_Type'Base
123 with
124 Post => (if X > 0.0 and then Y = 0.0 then Arctan'Result = 0.0);
126 function Arctan
127 (Y : Float_Type'Base;
128 X : Float_Type'Base := 1.0;
129 Cycle : Float_Type'Base) return Float_Type'Base
130 with
131 Post => (if X > 0.0 and then Y = 0.0 then Arctan'Result = 0.0);
133 function Arccot
134 (X : Float_Type'Base;
135 Y : Float_Type'Base := 1.0) return Float_Type'Base
136 with
137 Post => (if X > 0.0 and then Y = 0.0 then Arccot'Result = 0.0);
139 function Arccot
140 (X : Float_Type'Base;
141 Y : Float_Type'Base := 1.0;
142 Cycle : Float_Type'Base) return Float_Type'Base
143 with
144 Post => (if X > 0.0 and then Y = 0.0 then Arccot'Result = 0.0);
146 function Sinh (X : Float_Type'Base) return Float_Type'Base with
147 Post => (if X = 0.0 then Sinh'Result = 0.0);
149 function Cosh (X : Float_Type'Base) return Float_Type'Base with
150 Post => Cosh'Result >= 1.0
151 and then (if X = 0.0 then Cosh'Result = 1.0);
153 function Tanh (X : Float_Type'Base) return Float_Type'Base with
154 Post => Tanh'Result in -1.0 .. 1.0
155 and then (if X = 0.0 then Tanh'Result = 0.0);
157 function Coth (X : Float_Type'Base) return Float_Type'Base with
158 Post => abs Coth'Result >= 1.0;
160 function Arcsinh (X : Float_Type'Base) return Float_Type'Base with
161 Post => (if X = 0.0 then Arcsinh'Result = 0.0);
163 function Arccosh (X : Float_Type'Base) return Float_Type'Base with
164 Post => Arccosh'Result >= 0.0
165 and then (if X = 1.0 then Arccosh'Result = 0.0);
167 function Arctanh (X : Float_Type'Base) return Float_Type'Base with
168 Post => (if X = 0.0 then Arctanh'Result = 0.0);
170 function Arccoth (X : Float_Type'Base) return Float_Type'Base;
172 end Ada.Numerics.Generic_Elementary_Functions;