File : s-lilodo-ada.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . L I B M _ L O N G _ D O U B L E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2015-2016, 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 -- --
19 -- --
20 -- --
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 is the Ada Cert Math specific version of s-lilodo.ads
33
34 with System.Libm_Prefix;
35
36 -- @llrset Libm
37 -- LLR Libm
38 -- ========
39
40 package System.Libm_Long_Double is
41 pragma Pure;
42
43 package SLP renames System.Libm_Prefix;
44
45 -- This package provides an implementation of the various C99 functions
46 -- used in the Ada run time. It is intended to be used for targets that
47 -- do not have a C math library, or where the C math library isn't of
48 -- sufficient quality and accuracy to meet Ada requirements.
49
50 -- In case of error conditions, NaNs or infinities are returned as
51 -- recommended in clause F.9 of the C99 standard. When called from C code,
52 -- the implementation behaves as if the FENV_ACCESS state is off, assuming
53 -- default rounding behavior and exception behavior.
54
55 -- The following C99 elementary functions are provided:
56
57 -- Acos, Acosh, Asin, Asinh, Atan, Atan2, Atanh, Cosh, Exp, Exp2, Log,
58 -- Log1p, Log2, Pow, Sin, Sinh, Tan, Tanh
59
60 -- All functions with a NaN argument return a NaN result, except where
61 -- stated otherwise. Unless otherwise specified, where the symbol +- occurs
62 -- in both an argument and the result, the result has the same sign as
63 -- the argument.
64
65 -- Each function lists C special values, Ada expected values as well as
66 -- Ada accuracy requirements the function meets. For accuracy requirements
67 -- the maximum relative error (abbreviated as MRE) is given, as well as
68 -- the domain for which the accuracy is guaranteed, where applicable.
69 -- The maximum relative error is expressed as multiple of Eps,
70 -- where Eps is Long_Long_Float'Model_Epsilon.
71
72 -- What about principal branch ???
73
74 ----------
75 -- Acos --
76 ----------
77
78 function Acos (X : Long_Long_Float) return Long_Long_Float
79 with Export, Convention => C, External_Name => SLP.Prefix & "acosl";
80 -- @llr acos (Long_Long_Float) Special Values
81 -- The Acos function shall return the following special values:
82 --
83 -- C99 special values:
84 -- Acos (1) = +0
85 -- Acos (x) = NaN if abs (x) > 1
86 --
87 -- Ada expected values:
88 -- Acos (0) = Pi/2.0 (tightly approximated)
89 -- Acos (-1) = Pi (tightly approximated)
90 -- Acos (x) return a result in [0, Pi] radians
91 --
92 -- @llr acos (Long_Long_Float) Accuracy
93 -- The Acos function shall return the inverse cosine of <X> with the
94 -- following accuracy:
95 --
96 -- Ada accuracy requirements:
97 -- MRE <= 4.0 * Eps
98
99 -----------
100 -- Acosh --
101 -----------
102
103 function Acosh (X : Long_Long_Float) return Long_Long_Float
104 with Export, Convention => C, External_Name => SLP.Prefix & "acoshl";
105 -- @llr acosh (Long_Long_Float) Special Values
106 -- The Acosh function shall return the following special values:
107 --
108 -- C99 special values:
109 -- Acosh (1) = +0
110 -- Acosh (x) = NaN if abs X > 1
111 -- Acosh (+INF) = +INF
112 --
113 -- @llr acosh (Long_Long_Float) Accuracy
114 -- The Acosh function shall return the inverse hyperbolic tangent of <X>
115 -- with the following accuracy:
116 --
117 -- Ada accuracy requirements:
118 -- MRE <= 8.0 * Eps
119
120 ----------
121 -- Asin --
122 ----------
123
124 function Asin (X : Long_Long_Float) return Long_Long_Float
125 with Export, Convention => C, External_Name => SLP.Prefix & "asinl";
126 -- @llr asin (Long_Long_Float) Special Values
127 -- The Asin function shall return the following special values:
128 --
129 -- C99 special values:
130 -- Asin (+-0) = +-0
131 -- Asin (x) = NaN if abs (x) > 1
132 --
133 -- Ada expected values:
134 -- Asin (1) = Pi/2.0 (tightly approximated)
135 -- Asin (-1) = -Pi/2 (tightly approximated)
136 -- Asin (x) return a result in [-Pi/2, Pi/2] radians
137 --
138 -- @llr asin (Long_Long_Float) Accuracy
139 -- The Asin function shall return the inverse sine of <X> with the
140 -- following accuracy:
141 --
142 -- Ada accuracy requirements:
143 -- MRE <= 4.0 * Eps
144
145 -----------
146 -- Asinh --
147 -----------
148
149 function Asinh (X : Long_Long_Float) return Long_Long_Float
150 with Export, Convention => C, External_Name => SLP.Prefix & "asinhl";
151 -- @llr asinh (Long_Long_Float) Special Values
152 -- The Asinh function shall return the following special values:
153 --
154 -- C99 special values:
155 -- Asinh (0) = 0
156 -- Asinh (+INF) = +INF
157 --
158 -- @llr asinh (Long_Long_Float) Accuracy
159 -- The Asinh function shall return the inverse hyperbolic sine of <X>
160 -- with the following accuracy:
161 --
162 -- Ada accuracy requirements:
163 -- MRE <= 8.0 * Eps
164
165 ----------
166 -- Atan --
167 ----------
168
169 function Atan (X : Long_Long_Float) return Long_Long_Float
170 with Export, Convention => C, External_Name => SLP.Prefix & "atanl";
171 -- @llr atan (Long_Long_Float) Special Values
172 -- The Atan function shall return the following special values:
173 --
174 -- C99 special values:
175 -- Atan (+-0) = +-Pi
176 -- Atan2 (+-INF) = +-0.5 * Pi
177 --
178 -- C expected values:
179 -- Atan (x) return a result in [-Pi/2, Pi/2]
180
181 -----------
182 -- Atan2 --
183 -----------
184
185 function Atan2
186 (Y : Long_Long_Float;
187 X : Long_Long_Float) return Long_Long_Float
188 with Export, Convention => C, External_Name => SLP.Prefix & "atan2l";
189 -- @llr atan2 (Long_Long_Float; Long_Long_Float) Special Values
190 -- The Atan2 function shall return the following special values:
191 --
192 -- C99 special values:
193 -- Atan2 (+-0, -0) = +-Pi
194 -- Atan2 (+-0, +0) = +-0
195 -- Atan2 (+-0, x) = +-Pi, if x < 0
196 -- Atan2 (+-0, x) = +-0, if x > 0
197 -- Atan2 (y, +-0) = -0.5 * Pi, if y < 0
198 -- Atan2 (y, +-0) = 0.5 * Pi, if y > 0
199 -- Atan2 (+-y, -INF) = +-Pi, if y > 0 and y is finite
200 -- (tightly approximated)
201 -- Atan2 (+-y, -INF) = +-0, if y < 0 and y is finite
202 -- Atan2 (+-INF, x) = +-0.5 * Pi, if x is finite
203 -- (tightly approximated)
204 -- Atan2 (+-INF, -INF) = +-0.75 * Pi (tightly approximated)
205 -- Atan2 (+-INF, +INF) = +-0.25 * Pi (tightly approximated)
206 --
207 -- Ada expected values:
208 -- Atan2 (y, x) return a result in [-Pi, Pi]
209 --
210 -- @llr atan2 (Long_Long_Float; Long_Long_Float) Accuracy
211 -- The Atan2 function shall return the inverse tangent of <Y> / <X>
212 -- with the following accuracy:
213 --
214 -- Ada accuracy requirements:
215 -- MRE <= 4.0 * Eps
216
217 -----------
218 -- Atanh --
219 -----------
220
221 function Atanh (X : Long_Long_Float) return Long_Long_Float
222 with Export, Convention => C, External_Name => SLP.Prefix & "atanhl";
223 -- @llr atanh (Long_Long_Float) Special Values
224 -- The Atanh function shall return the following special values:
225 --
226 -- C99 special values:
227 -- Atanh (0) = 0
228 -- Atanh (+-1) = +- INF
229 -- Atanh (X) = NaN for abs X > 1
230 --
231 -- @llr atanh (Long_Long_Float) Accuracy
232 -- The Atanh function shall return the inverse hyperbolic tangent of <X>
233 -- with the following accuracy:
234 --
235 -- Ada accuracy requirements:
236 -- MRE <= 8.0 * Eps
237
238 ---------
239 -- Cos --
240 ---------
241
242 function Cos (X : Long_Long_Float) return Long_Long_Float
243 with Export, Convention => C, External_Name => SLP.Prefix & "cosl";
244 -- @llr cos (Long_Long_Float) Special Values
245 -- The Cos function shall return the following special values:
246 --
247 -- C99 special values:
248 -- Cos (+-0) = 1
249 -- Cos (+-INF) = NaN
250 --
251 -- Ada expected values:
252 -- abs (Cos (x)) <= 1
253 --
254 -- @llr cos (Long_Long_Float) Accuracy
255 -- The Cos function shall return the cosine of <X>
256 -- with the following accuracy:
257 --
258 -- Ada accuracy requirements:
259 -- MRE <= 2.0 * Eps
260
261 ----------
262 -- Cosh --
263 ----------
264
265 function Cosh (X : Long_Long_Float) return Long_Long_Float
266 with Export, Convention => C, External_Name => SLP.Prefix & "coshl";
267 -- @llr cosh (Long_Long_Float) Special Values
268 -- The Cosh function shall return the following special values:
269 --
270 -- C99 special values:
271 -- Cosh (+-0) = 1
272 -- Cosh (+-INF) = +INF
273 --
274 -- Ada expected values:
275 -- abs (Cosh (x)) > 1
276 --
277 -- @llr cosh (Long_Long_Float) Accuracy
278 -- The Cosh function shall return the hyperbolic cosine of <X>
279 -- with the following accuracy:
280 --
281 -- Ada accuracy requirements:
282 -- MRE <= 8.0 * Eps
283
284 ---------
285 -- Exp --
286 ---------
287
288 function Exp (X : Long_Long_Float) return Long_Long_Float
289 with Export, Convention => C, External_Name => SLP.Prefix & "expl";
290 -- @llr exp (Long_Long_Float) Special Values
291 -- The Exp function shall return the following special values:
292 --
293 -- C99 special values:
294 -- Exp (+-0) = 1
295 -- Exp (-INF) = +0
296 -- Exp (+INF) = +INF
297 --
298 -- @llr exp (Long_Long_Float) Accuracy
299 -- The Exp function shall return the exponential of <X>
300 -- with the following accuracy:
301 --
302 -- Ada accuracy requirements:
303 -- MRE <= 4.0 * Eps
304
305 ----------
306 -- Exp2 --
307 ----------
308
309 function Exp2 (X : Long_Long_Float) return Long_Long_Float
310 with Export, Convention => C, External_Name => SLP.Prefix & "exp2l";
311 -- @llr exp2 (Long_Long_Float) Special Values
312 -- The Exp2 function shall return the following special values:
313 --
314 -- C99 special values:
315 -- Exp2 (+-0) = 1
316 -- Exp2 (-INF) = +0
317 -- Exp2 (+INF) = +INF
318 --
319 -- @llr exp2 (Long_Long_Float) Accuracy
320 -- The Exp2 function shall return the exponential of <X> in base 2
321 -- with the following accuracy:
322 --
323 -- Accuracy requirements:
324 -- MRE <= 4.0 * Eps
325
326 ---------
327 -- Log --
328 ---------
329
330 function Log (X : Long_Long_Float) return Long_Long_Float
331 with Export, Convention => C, External_Name => SLP.Prefix & "logl";
332 -- @llr log (Long_Long_Float) Special Values
333 -- The Log function shall return the following special values:
334 --
335 -- C99 special values:
336 -- Log (+-0) = -INF
337 -- Log (1) = +0
338 -- Log (x) = NaN if x<0
339 -- Log (+INF) = +INF
340 --
341 -- @llr log (Long_Long_Float) Accuracy
342 -- The Log function shall return the logarithm of <X>
343 -- with the following accuracy:
344 --
345 -- Ada accuracy requirements:
346 -- MRE <= 4.0 * Eps
347
348 -----------
349 -- Log1p --
350 -----------
351
352 function Log1p (X : Long_Long_Float) return Long_Long_Float
353 with Export, Convention => C, External_Name => SLP.Prefix & "log1pl";
354 -- @llr log1p (Long_Long_Float) Special Values:
355 -- The Log1p function shall return the following special values:
356 --
357 -- C99 special values:
358 -- Log1p (+-0) = -INF
359 -- Log1p (1) = +0
360 -- Log1p (x) = NaN if x<0
361 -- Log1p (+INF) = +INF
362 --
363 -- @llr log1p (Long_Long_Float) Accuracy
364 -- The Log1p function shall return the logarithm of <X> + 1
365 -- with the following accuracy:
366 --
367 -- Accuracy requirements:
368 -- MRE <= 4.0 * Eps
369
370 ----------
371 -- Log2 --
372 ----------
373
374 function Log2 (X : Long_Long_Float) return Long_Long_Float
375 with Export, Convention => C, External_Name => SLP.Prefix & "log2l";
376 -- @llr log2 (Long_Long_Float) Special Values
377 -- The Log2 function shall return the following special values:
378 --
379 -- C99 Special values:
380 -- Log2 (+-0) = -INF
381 -- Log2 (1) = +0
382 -- Log2 (x) = NaN if x<0
383 -- Log2 (+INF) = +INF
384 --
385 -- @llr log2 (Long_Long_Float) Accuracy
386 -- The Log2 function shall return the logarithm of <X> in base 2
387 -- with the following accuracy:
388 --
389 -- Accuracy requirements:
390 -- MRE <= 4.0 * Eps
391 ---------
392 -- Pow --
393 ---------
394
395 function Pow (Left, Right : Long_Long_Float) return Long_Long_Float
396 with Export, Convention => C, External_Name => SLP.Prefix & "powl";
397 -- @llr pow (Long_Long_Float; Long_Long_Float) Special Values
398 -- The Pow function shall return the following special values
399 --
400 -- C99 Special values:
401 -- Pow (+-0, y) = +-INF, if y < 0 and y an odd integer
402 -- Pow (+-0, y) = +INF, if y < 0 and y not an odd integer
403 -- Pow (+-0, y) = +-0 if y > 0 and y an odd integer
404 -- Pow (+-0, y) = +0 if y > 0 and y not an odd integer
405 -- Pow (-1, +-INF) = 1
406 -- Pow (1, y) = 1 for any y, even a NaN
407 -- Pow (x, +-0) = 1 for any x, even a NaN
408 -- Pow (x, y) = NaN, if x < 0 and both x and y finite and not integer
409 -- Pow (x, -INF) = +INF if abs (x) < 1
410 -- Pow (x, -INF) = +0 if abs (x) > 1
411 -- Pow (x, +INF) = +0 if abs (x) < 1
412 -- Pow (x, +INF) = +INF if abs (x) > 1
413 -- Pow (-INF, y) = -0 if y < 0 and y an odd integer
414 -- Pow (-INF, y) = +0 if y < 0 and y not an odd integer
415 -- Pow (-INF, y) = -INF if y > 0 and y an odd integer
416 -- Pow (-INF, y) = +INF if y > 0 and y not an odd integer
417 -- Pow (+INF, y) = +0 if y < 0
418 -- Pow (+INF, y) = +INF if y > 0
419 --
420 -- @llr pow (Long_Long_Float; Long_Long_Float) Accuracy
421 -- The Pow function shall return <Left> to the power of <Right>
422 -- with the following accuracy:
423 --
424 -- Ada Accuracy requirements:
425 -- MRE <= (4.0 + abs (x * Log (y)) / 32) * Eps
426
427 ---------
428 -- Sin --
429 ---------
430
431 function Sin (X : Long_Long_Float) return Long_Long_Float
432 with Export, Convention => C, External_Name => SLP.Prefix & "sinl";
433 -- @llr sin (Long_Long_Float) Special Values
434 -- The Sin function shall return the following special values
435 --
436 -- C99 special values:
437 -- Sin (+-0) = +-0
438 -- Sin (+-INF) = NaN
439 --
440 -- @llr sin (Long_Long_Float) Accuracy
441 -- The Sin function shall return the sine of <X>
442 -- with the following accuracy:
443 --
444 -- Ada accuracy requirements:
445 -- MRE <= 2.0 * Eps
446
447 ----------
448 -- Sinh --
449 ----------
450
451 function Sinh (X : Long_Long_Float) return Long_Long_Float
452 with Export, Convention => C, External_Name => SLP.Prefix & "sinhl";
453 -- @llr sinh (Long_Long_Float) Special Values
454 -- The Sinh function shall return the following special values:
455 --
456 -- C99 Special values:
457 -- Sinh (+-0) = +-0
458 -- Sinh (+-INF) = +-INF
459 --
460 -- @llr sinh (Long_Long_Float) Accuracy
461 -- The Sinh function shall return the hyperbolic sine of <X>
462 -- with the following accuracy:
463 --
464 -- Ada accuracy requirements:
465 -- MRE <= 8.0 * Eps
466
467 ----------
468 -- Sqrt --
469 ----------
470
471 function Sqrt (X : Long_Long_Float) return Long_Long_Float
472 with Convention => C;
473 -- The Sqrt function shall return the following special values:
474 --
475 -- C99 special values:
476 -- Sqrt (+-0) = +-0
477 -- Sqrt (INF) = INF
478 -- Sqrt (X) = NaN, for X < 0.0
479
480 ---------
481 -- Tan --
482 ---------
483
484 function Tan (X : Long_Long_Float) return Long_Long_Float
485 with Export, Convention => C, External_Name => SLP.Prefix & "tanl";
486 -- @llr tan (Long_Long_Float) Special Values
487 -- The Tan function shall return the following special values:
488 --
489 -- C99 special values:
490 -- Tan (+-0) = +0
491 -- Tan (+-INF) = NaN
492 --
493 -- @llr tan (Long_Long_Float) Accuracy
494 -- The Tan function shall return the tangent of <X>
495 -- with the following accuracy:
496 --
497 -- Ada accuracy requirements:
498 -- MRE <= 4.0 * Eps
499
500 ----------
501 -- Tanh --
502 ----------
503
504 function Tanh (X : Long_Long_Float) return Long_Long_Float
505 with Export, Convention => C, External_Name => SLP.Prefix & "tanhl";
506 -- @llr tanh (Long_Long_Float) Special Values
507 -- The Tanh function shall return the following special values:
508 --
509 -- C99 special values:
510 -- Tanh (+-0) = +-0
511 -- Tanh (+-INF) = +-1
512 --
513 -- @llr tanh (Long_Long_Float) Accuracy
514 -- The Tanh function shall return the hyperbolic tangent of <X>
515 -- with the following accuracy:
516 --
517 -- Ada accuracy requirements:
518 -- MRE <= 8.0 * Eps
519
520 private
521 function Identity (X : Long_Long_Float) return Long_Long_Float is (X);
522
523 function Infinity return Long_Long_Float
524 with Import, Convention => Intrinsic, External_Name => "__builtin_infl";
525
526 function NaN return Long_Long_Float is (Infinity - Infinity);
527
528 function Exact (X : Long_Long_Float) return Long_Long_Float is (X);
529
530 function Epsilon return Long_Long_Float is (Long_Long_Float'Model_Epsilon);
531
532 function Maximum_Relative_Error (X : Long_Long_Float) return Float is
533 (Float (0.0 * X));
534
535 end System.Libm_Long_Double;