File : s-libdou-ada.ads


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT COMPILER COMPONENTS                         --
   4 --                                                                          --
   5 --                    S Y S T E M . L I B M _ D O U B L E                   --
   6 --                                                                          --
   7 --                                 S p e c                                  --
   8 --                                                                          --
   9 --          Copyright (C) 2014-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-libdou.ads
  33 
  34 with System.Libm_Prefix;
  35 
  36 --  @llrset Libm
  37 --  LLR Libm
  38 --  ========
  39 
  40 package System.Libm_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_Float'Model_Epsilon.
  71 
  72    --  What about principal branch ???
  73 
  74    ----------
  75    -- Acos --
  76    ----------
  77 
  78    function Acos (X : Long_Float) return Long_Float
  79      with Export, Convention => C, External_Name => SLP.Prefix & "acos";
  80    --  @llr acos (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_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_Float) return Long_Float
 104      with Export, Convention => C, External_Name => SLP.Prefix & "acosh";
 105    --  @llr acosh (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_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_Float) return Long_Float
 125      with Export, Convention => C, External_Name => SLP.Prefix & "asin";
 126    --  @llr asin (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_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_Float) return Long_Float
 150      with Export, Convention => C, External_Name => SLP.Prefix & "asinh";
 151    --  @llr asinh (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_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_Float) return Long_Float
 170      with Export, Convention => C, External_Name => SLP.Prefix & "atan";
 171    --  @llr atan (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 (Y : Long_Float; X : Long_Float) return Long_Float
 186      with Export, Convention => C, External_Name => SLP.Prefix & "atan2";
 187    --  @llr atan2 (Long_Float; Long_Float) Special Values
 188    --  The Atan2 function shall return the following special values:
 189    --
 190    --  C99 special values:
 191    --    Atan2 (+-0, -0)     = +-Pi
 192    --    Atan2 (+-0, +0)     = +-0
 193    --    Atan2 (+-0, x)      = +-Pi,        if x < 0
 194    --    Atan2 (+-0, x)      = +-0,         if x > 0
 195    --    Atan2 (y, +-0)      = -0.5 * Pi,   if y < 0
 196    --    Atan2 (y, +-0)      =  0.5 * Pi,   if y > 0
 197    --    Atan2 (+-y, -INF)   = +-Pi,        if y > 0 and y is finite
 198    --      (tightly approximated)
 199    --    Atan2 (+-y, -INF)   = +-0,         if y < 0 and y is finite
 200    --    Atan2 (+-INF, x)    = +-0.5 * Pi,  if x is finite
 201    --      (tightly approximated)
 202    --    Atan2 (+-INF, -INF) = +-0.75 * Pi (tightly approximated)
 203    --    Atan2 (+-INF, +INF) = +-0.25 * Pi (tightly approximated)
 204    --
 205    --  Ada expected values:
 206    --    Atan2 (y, x) return a result in [-Pi, Pi]
 207    --
 208    --  @llr atan2 (Long_Float; Long_Float) Accuracy
 209    --  The Atan2 function shall return the inverse tangent of <Y> / <X>
 210    --  with the following accuracy:
 211    --
 212    --  Ada accuracy requirements:
 213    --    MRE <= 4.0 * Eps
 214 
 215    -----------
 216    -- Atanh --
 217    -----------
 218 
 219    function Atanh (X : Long_Float) return Long_Float
 220      with Export, Convention => C, External_Name => SLP.Prefix & "atanh";
 221    --  @llr atanh (Long_Float) Special Values
 222    --  The Atanh function shall return the following special values:
 223    --
 224    --  C99 special values:
 225    --    Atanh (0) = 0
 226    --    Atanh (+-1) = +- INF
 227    --    Atanh (X) = NaN for abs X > 1
 228    --
 229    --  @llr atanh (Long_Float) Accuracy
 230    --  The Atanh function shall return the inverse hyperbolic tangent of <X>
 231    --  with the following accuracy:
 232    --
 233    --  Ada accuracy requirements:
 234    --    MRE <= 8.0 * Eps
 235 
 236    ---------
 237    -- Cos --
 238    ---------
 239 
 240    function Cos (X : Long_Float) return Long_Float
 241      with Export, Convention => C, External_Name => SLP.Prefix & "cos";
 242    --  @llr cos (Long_Float) Special Values
 243    --  The Cos function shall return the following special values:
 244    --
 245    --  C99 special values:
 246    --    Cos (+-0)   = 1
 247    --    Cos (+-INF) = NaN
 248    --
 249    --  Ada expected values:
 250    --    abs (Cos (x)) <= 1
 251    --
 252    --  @llr cos (Long_Float) Accuracy
 253    --  The Cos function shall return the cosine of <X>
 254    --  with the following accuracy:
 255    --
 256    --  Ada accuracy requirements:
 257    --    MRE <= 2.0 * Eps
 258 
 259    ----------
 260    -- Cosh --
 261    ----------
 262 
 263    function Cosh (X : Long_Float) return Long_Float
 264      with Export, Convention => C, External_Name => SLP.Prefix & "cosh";
 265    --  @llr cosh (Long_Float) Special Values
 266    --  The Cosh function shall return the following special values:
 267    --
 268    --  C99 special values:
 269    --    Cosh (+-0)   = 1
 270    --    Cosh (+-INF) = +INF
 271    --
 272    --  Ada expected values:
 273    --    abs (Cosh (x)) > 1
 274    --
 275    --  @llr cosh (Long_Float) Accuracy
 276    --  The Cosh function shall return the hyperbolic cosine of <X>
 277    --  with the following accuracy:
 278    --
 279    --  Ada accuracy requirements:
 280    --    MRE <= 8.0 * Eps
 281 
 282    ---------
 283    -- Exp --
 284    ---------
 285 
 286    function Exp (X : Long_Float) return Long_Float
 287      with Export, Convention => C, External_Name => SLP.Prefix & "exp";
 288    --  @llr exp (Long_Float) Special Values
 289    --  The Exp function shall return the following special values:
 290    --
 291    --  C99 special values:
 292    --    Exp (+-0)  = 1
 293    --    Exp (-INF) = +0
 294    --    Exp (+INF) = +INF
 295    --
 296    --  @llr exp (Long_Float) Accuracy
 297    --  The Exp function shall return the exponential of <X>
 298    --  with the following accuracy:
 299    --
 300    --  Ada accuracy requirements:
 301    --    MRE <= 4.0 * Eps
 302 
 303    ----------
 304    -- Exp2 --
 305    ----------
 306 
 307    function Exp2 (X : Long_Float) return Long_Float
 308      with Export, Convention => C, External_Name => SLP.Prefix & "exp2";
 309    --  @llr exp2 (Long_Float) Special Values
 310    --  The Exp2 function shall return the following special values:
 311    --
 312    --  C99 special values:
 313    --    Exp2 (+-0)  = 1
 314    --    Exp2 (-INF) = +0
 315    --    Exp2 (+INF) = +INF
 316    --
 317    --  @llr exp2 (Long_Float) Accuracy
 318    --  The Exp2 function shall return the exponential of <X> in base 2
 319    --  with the following accuracy:
 320    --
 321    --  Accuracy requirements:
 322    --    MRE <= 4.0 * Eps
 323 
 324    ---------
 325    -- Log --
 326    ---------
 327 
 328    function Log (X : Long_Float) return Long_Float
 329      with Export, Convention => C, External_Name => SLP.Prefix & "log";
 330    --  @llr log (Long_Float) Special Values
 331    --  The Log function shall return the following special values:
 332    --
 333    --  C99 special values:
 334    --    Log (+-0)  = -INF
 335    --    Log (1)    = +0
 336    --    Log (x)    = NaN if x<0
 337    --    Log (+INF) = +INF
 338    --
 339    --  @llr log (Long_Float) Accuracy
 340    --  The Log function shall return the logarithm of <X>
 341    --  with the following accuracy:
 342    --
 343    --  Ada accuracy requirements:
 344    --    MRE <= 4.0 * Eps
 345 
 346    -----------
 347    -- Log1p --
 348    -----------
 349 
 350    function Log1p (X : Long_Float) return Long_Float
 351      with Export, Convention => C, External_Name => SLP.Prefix & "log1p";
 352    --  @llr log1p (Long_Float) Special Values:
 353    --  The Log1p function shall return the following special values:
 354    --
 355    --  C99 special values:
 356    --    Log1p (+-0)  = -INF
 357    --    Log1p (1)    = +0
 358    --    Log1p (x)    = NaN if x<0
 359    --    Log1p (+INF) = +INF
 360    --
 361    --  @llr log1p (Long_Float) Accuracy
 362    --  The Log1p function shall return the logarithm of <X> + 1
 363    --  with the following accuracy:
 364    --
 365    --  Accuracy requirements:
 366    --    MRE <= 4.0 * Eps
 367 
 368    ----------
 369    -- Log2 --
 370    ----------
 371 
 372    function Log2 (X : Long_Float) return Long_Float
 373      with Export, Convention => C, External_Name => SLP.Prefix & "log2";
 374    --  @llr log2 (Long_Float) Special Values
 375    --  The Log2 function shall return the following special values:
 376    --
 377    --  C99 Special values:
 378    --    Log2 (+-0)  = -INF
 379    --    Log2 (1)    = +0
 380    --    Log2 (x)    = NaN if x<0
 381    --    Log2 (+INF) = +INF
 382    --
 383    --  @llr log2 (Long_Float) Accuracy
 384    --  The Log2 function shall return the logarithm of <X> in base 2
 385    --  with the following accuracy:
 386    --
 387    --  Accuracy requirements:
 388    --    MRE <= 4.0 * Eps
 389    ---------
 390    -- Pow --
 391    ---------
 392 
 393    function Pow (Left, Right : Long_Float) return Long_Float
 394      with Export, Convention => C, External_Name => SLP.Prefix & "pow";
 395    --  @llr pow (Long_Float; Long_Float) Special Values
 396    --  The Pow function shall return the following special values
 397    --
 398    --  C99 Special values:
 399    --    Pow (+-0, y)    = +-INF, if y < 0 and y an odd integer
 400    --    Pow (+-0, y)    = +INF, if y < 0 and y not an odd integer
 401    --    Pow (+-0, y)    = +-0   if y > 0 and y an odd integer
 402    --    Pow (+-0, y)    = +0    if y > 0 and y not an odd integer
 403    --    Pow (-1, +-INF) = 1
 404    --    Pow (1, y)      = 1 for any y, even a NaN
 405    --    Pow (x, +-0)    = 1 for any x, even a NaN
 406    --    Pow (x, y)  = NaN, if x < 0 and both x and y finite and not integer
 407    --    Pow (x, -INF)   = +INF      if abs (x) < 1
 408    --    Pow (x, -INF)   = +0        if abs (x) > 1
 409    --    Pow (x, +INF)   = +0        if abs (x) < 1
 410    --    Pow (x, +INF)   = +INF      if abs (x) > 1
 411    --    Pow (-INF, y)   = -0        if y < 0 and y an odd integer
 412    --    Pow (-INF, y)   = +0        if y < 0 and y not an odd integer
 413    --    Pow (-INF, y)   = -INF      if y > 0 and y an odd integer
 414    --    Pow (-INF, y)   = +INF      if y > 0 and y not an odd integer
 415    --    Pow (+INF, y)   = +0        if y < 0
 416    --    Pow (+INF, y)   = +INF      if y > 0
 417    --
 418    --  @llr pow (Long_Float; Long_Float) Accuracy
 419    --  The Pow function shall return <Left> to the power of <Right>
 420    --  with the following accuracy:
 421    --
 422    --  Ada Accuracy requirements:
 423    --    MRE <= (4.0 + abs (x * Log (y)) / 32) * Eps
 424 
 425    ---------
 426    -- Sin --
 427    ---------
 428 
 429    function Sin (X : Long_Float) return Long_Float
 430      with Export, Convention => C, External_Name => SLP.Prefix & "sin";
 431    --  @llr sin (Long_Float) Special Values
 432    --  The Sin function shall return the following special values
 433    --
 434    --  C99 special values:
 435    --    Sin (+-0)   = +-0
 436    --    Sin (+-INF) = NaN
 437    --
 438    --  @llr sin (Long_Float) Accuracy
 439    --  The Sin function shall return the sine of <X>
 440    --  with the following accuracy:
 441    --
 442    --  Ada accuracy requirements:
 443    --    MRE <= 2.0 * Eps
 444 
 445    ----------
 446    -- Sinh --
 447    ----------
 448 
 449    function Sinh (X : Long_Float) return Long_Float
 450      with Export, Convention => C, External_Name => SLP.Prefix & "sinh";
 451    --  @llr sinh (Long_Float) Special Values
 452    --  The Sinh function shall return the following special values:
 453    --
 454    --  C99 Special values:
 455    --    Sinh (+-0)   = +-0
 456    --    Sinh (+-INF) = +-INF
 457    --
 458    --  @llr sinh (Long_Float) Accuracy
 459    --  The Sinh function shall return the hyperbolic sine of <X>
 460    --  with the following accuracy:
 461    --
 462    --  Ada accuracy requirements:
 463    --    MRE <= 8.0 * Eps
 464 
 465    ----------
 466    -- Sqrt --
 467    ----------
 468 
 469    function Sqrt (X : Long_Float) return Long_Float
 470      with Convention => C;
 471    --  The Sqrt function shall return the following special values:
 472    --
 473    --  C99 special values:
 474    --    Sqrt (+-0) = +-0
 475    --    Sqrt (INF) = INF
 476    --    Sqrt (X)   = NaN, for X < 0.0
 477 
 478    ---------
 479    -- Tan --
 480    ---------
 481 
 482    function Tan (X : Long_Float) return Long_Float
 483      with Export, Convention => C, External_Name => SLP.Prefix & "tan";
 484    --  @llr tan (Long_Float) Special Values
 485    --  The Tan function shall return the following special values:
 486    --
 487    --  C99 special values:
 488    --    Tan (+-0)   = +0
 489    --    Tan (+-INF) = NaN
 490    --
 491    --  @llr tan (Long_Float) Accuracy
 492    --  The Tan function shall return the tangent of <X>
 493    --  with the following accuracy:
 494    --
 495    --  Ada accuracy requirements:
 496    --    MRE <= 4.0 * Eps
 497 
 498    ----------
 499    -- Tanh --
 500    ----------
 501 
 502    function Tanh (X : Long_Float) return Long_Float
 503      with Export, Convention => C, External_Name => SLP.Prefix & "tanh";
 504    --  @llr tanh (Long_Float) Special Values
 505    --  The Tanh function shall return the following special values:
 506    --
 507    --  C99 special values:
 508    --    Tanh (+-0) = +-0
 509    --    Tanh (+-INF) = +-1
 510    --
 511    --  @llr tanh (Long_Float) Accuracy
 512    --  The Tanh function shall return the hyperbolic tangent of <X>
 513    --  with the following accuracy:
 514    --
 515    --  Ada accuracy requirements:
 516    --    MRE <= 8.0 * Eps
 517 
 518 private
 519    function Identity (X : Long_Float) return Long_Float is (X);
 520 
 521    function Infinity return Long_Float
 522      with Import, Convention => Intrinsic, External_Name => "__builtin_inf";
 523 
 524    function NaN return Long_Float is (Infinity - Infinity);
 525 
 526    function Exact (X : Long_Long_Float) return Long_Float is (Long_Float (X));
 527 
 528    function Epsilon return Long_Float is (Long_Float'Model_Epsilon);
 529 
 530    function Maximum_Relative_Error (X : Long_Float) return Float is
 531      (Float (0.0 * X));
 532 
 533 end System.Libm_Double;