]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - math/math.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / math / math.h
index 9161412f984778793c5ffd426e3f478b10aeb80a..c7ff16971e98662081e3192a1269038e9419af59 100644 (file)
@@ -1,5 +1,5 @@
 /* Declarations for math functions.
-   Copyright (C) 1991-1993,1995-1999,2001,2002 Free Software Foundation, Inc.
+   Copyright (C) 1991-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -13,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 /*
  *     ISO C99 Standard: 7.12 Mathematics      <math.h>
@@ -31,15 +30,20 @@ __BEGIN_DECLS
 /* Get machine-dependent HUGE_VAL value (returned on overflow).
    On all IEEE754 machines, this is +Infinity.  */
 #include <bits/huge_val.h>
+#ifdef __USE_ISOC99
+# include <bits/huge_valf.h>
+# include <bits/huge_vall.h>
+
+/* Get machine-dependent INFINITY value.  */
+# include <bits/inf.h>
 
 /* Get machine-dependent NAN value (returned for some domain errors).  */
-#ifdef  __USE_ISOC99
 # include <bits/nan.h>
-#endif
+#endif /* __USE_ISOC99 */
+
 /* Get general and ISO C99 specific information.  */
 #include <bits/mathdef.h>
 
-
 /* The file <bits/mathcalls.h> contains the prototypes for all the
    actual math functions.  These macros are used for those prototypes,
    so we can easily declare each function as both `name' and `__name',
@@ -58,17 +62,17 @@ __BEGIN_DECLS
 #define __MATHDECL_1(type, function,suffix, args) \
   extern type __MATH_PRECNAME(function,suffix) args __THROW
 
-#define _Mdouble_              double
+#define _Mdouble_              double
 #define __MATH_PRECNAME(name,r)        __CONCAT(name,r)
-# define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_STD
-# define _Mdouble_END_NAMESPACE   __END_NAMESPACE_STD
+#define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_STD
+#define _Mdouble_END_NAMESPACE   __END_NAMESPACE_STD
 #include <bits/mathcalls.h>
 #undef _Mdouble_
 #undef _Mdouble_BEGIN_NAMESPACE
 #undef _Mdouble_END_NAMESPACE
 #undef __MATH_PRECNAME
 
-#if defined __USE_MISC || defined __USE_ISOC99
+#ifdef __USE_ISOC99
 
 
 /* Include the file of declarations again, this time using `float'
@@ -77,12 +81,8 @@ __BEGIN_DECLS
 # ifndef _Mfloat_
 #  define _Mfloat_             float
 # endif
-# define _Mdouble_             _Mfloat_
-# ifdef __STDC__
-#  define __MATH_PRECNAME(name,r) name##f##r
-# else
-#  define __MATH_PRECNAME(name,r) name/**/f/**/r
-# endif
+# define _Mdouble_             _Mfloat_
+# define __MATH_PRECNAME(name,r) name##f##r
 # define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
 # define _Mdouble_END_NAMESPACE   __END_NAMESPACE_C99
 # include <bits/mathcalls.h>
@@ -91,30 +91,54 @@ __BEGIN_DECLS
 # undef _Mdouble_END_NAMESPACE
 # undef        __MATH_PRECNAME
 
-# if (__STDC__ - 0 || __GNUC__ - 0) && !defined __NO_LONG_DOUBLE_MATH
+# if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
+     || defined __LDBL_COMPAT \
+     || defined _LIBC_TEST
+#  ifdef __LDBL_COMPAT
+
+#   ifdef __USE_ISOC99
+extern float __nldbl_nexttowardf (float __x, long double __y)
+                                 __THROW __attribute__ ((__const__));
+#    ifdef __REDIRECT_NTH
+extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
+                            __nldbl_nexttowardf)
+     __attribute__ ((__const__));
+extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
+                             nextafter) __attribute__ ((__const__));
+extern long double __REDIRECT_NTH (nexttowardl,
+                                  (long double __x, long double __y),
+                                  nextafter) __attribute__ ((__const__));
+#    endif
+#   endif
+
+#   undef __MATHDECL_1
+#   define __MATHDECL_2(type, function,suffix, args, alias) \
+  extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
+                            args, alias)
+#   define __MATHDECL_1(type, function,suffix, args) \
+  __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
+#  endif
+
 /* Include the file of declarations again, this time using `long double'
    instead of `double' and appending l to each function name.  */
 
 #  ifndef _Mlong_double_
 #   define _Mlong_double_      long double
 #  endif
-#  define _Mdouble_            _Mlong_double_
-#  ifdef __STDC__
-#   define __MATH_PRECNAME(name,r) name##l##r
-#  else
-#   define __MATH_PRECNAME(name,r) name/**/l/**/r
-#  endif
+#  define _Mdouble_            _Mlong_double_
+#  define __MATH_PRECNAME(name,r) name##l##r
 #  define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
 #  define _Mdouble_END_NAMESPACE   __END_NAMESPACE_C99
+#  define __MATH_DECLARE_LDOUBLE   1
 #  include <bits/mathcalls.h>
 #  undef _Mdouble_
-# undef _Mdouble_BEGIN_NAMESPACE
-# undef _Mdouble_END_NAMESPACE
+#  undef _Mdouble_BEGIN_NAMESPACE
+#  undef _Mdouble_END_NAMESPACE
 #  undef __MATH_PRECNAME
 
-# endif /* __STDC__ || __GNUC__ */
+# endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
 
-#endif /* Use misc or ISO C99.  */
+#endif /* Use ISO C99.  */
 #undef __MATHDECL_1
 #undef __MATHDECL
 #undef __MATHCALL
@@ -127,7 +151,7 @@ extern int signgam;
 
 
 /* ISO C99 defines some generic macros which work on any data type.  */
-#if __USE_ISOC99
+#ifdef __USE_ISOC99
 
 /* Get the architecture specific values describing the floating-point
    evaluation.  The following symbols will get defined:
@@ -165,16 +189,21 @@ extern int signgam;
 /* All floating-point numbers can be put in one of these categories.  */
 enum
   {
-    FP_NAN,
-# define FP_NAN FP_NAN
-    FP_INFINITE,
-# define FP_INFINITE FP_INFINITE
-    FP_ZERO,
-# define FP_ZERO FP_ZERO
-    FP_SUBNORMAL,
-# define FP_SUBNORMAL FP_SUBNORMAL
-    FP_NORMAL
-# define FP_NORMAL FP_NORMAL
+    FP_NAN =
+# define FP_NAN 0
+      FP_NAN,
+    FP_INFINITE =
+# define FP_INFINITE 1
+      FP_INFINITE,
+    FP_ZERO =
+# define FP_ZERO 2
+      FP_ZERO,
+    FP_SUBNORMAL =
+# define FP_SUBNORMAL 3
+      FP_SUBNORMAL,
+    FP_NORMAL =
+# define FP_NORMAL 4
+      FP_NORMAL
   };
 
 /* Return number of classification appropriate for X.  */
@@ -229,7 +258,7 @@ enum
       ? __isnan (x) : __isnanl (x))
 # endif
 
-/* Return nonzero value is X is positive or negative infinity.  */
+/* Return nonzero value if X is positive or negative infinity.  */
 # ifdef __NO_LONG_DOUBLE_MATH
 #  define isinf(x) \
      (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
@@ -245,8 +274,29 @@ enum
 # define MATH_ERRNO    1       /* errno set by math functions.  */
 # define MATH_ERREXCEPT        2       /* Exceptions raised by math functions.  */
 
+/* By default all functions support both errno and exception handling.
+   In gcc's fast math mode and if inline functions are defined this
+   might not be true.  */
+# ifndef __FAST_MATH__
+#  define math_errhandling     (MATH_ERRNO | MATH_ERREXCEPT)
+# endif
+
 #endif /* Use ISO C99.  */
 
+#ifdef __USE_GNU
+/* Return nonzero value if X is a signaling NaN.  */
+# ifdef __NO_LONG_DOUBLE_MATH
+#  define issignaling(x) \
+     (sizeof (x) == sizeof (float) ? __issignalingf (x) : __issignaling (x))
+# else
+#  define issignaling(x) \
+     (sizeof (x) == sizeof (float)                                           \
+      ? __issignalingf (x)                                                   \
+      : sizeof (x) == sizeof (double)                                        \
+      ? __issignaling (x) : __issignalingl (x))
+# endif
+#endif /* Use GNU.  */
+
 #ifdef __USE_MISC
 /* Support for various different standard error handling behaviors.  */
 typedef enum
@@ -265,7 +315,7 @@ extern _LIB_VERSION_TYPE _LIB_VERSION;
 #endif
 
 
-#ifdef __USE_SVID
+#ifdef __USE_MISC
 /* In SVID error handling, `matherr' is called with this description
    of the exceptional condition.
 
@@ -303,18 +353,18 @@ extern int matherr (struct exception *__exc);
 /* SVID mode specifies returning this large value instead of infinity.  */
 # define HUGE          3.40282347e+38F
 
-#else  /* !SVID */
+#else  /* !Misc.  */
 
 # ifdef __USE_XOPEN
 /* X/Open wants another strange constant.  */
 #  define MAXFLOAT     3.40282347e+38F
 # endif
 
-#endif /* SVID */
+#endif /* Misc.  */
 
 
 /* Some useful constants.  */
-#if defined __USE_BSD || defined __USE_XOPEN
+#if defined __USE_MISC || defined __USE_XOPEN
 # define M_E           2.7182818284590452354   /* e */
 # define M_LOG2E       1.4426950408889634074   /* log_2 e */
 # define M_LOG10E      0.43429448190325182765  /* log_10 e */
@@ -334,19 +384,19 @@ extern int matherr (struct exception *__exc);
    Therefore we provide as an extension constants with similar names as a
    GNU extension.  Provide enough digits for the 128-bit IEEE quad.  */
 #ifdef __USE_GNU
-# define M_El          2.7182818284590452353602874713526625L  /* e */
-# define M_LOG2El      1.4426950408889634073599246810018921 /* log_2 e */
-# define M_LOG10El     0.4342944819032518276511289189166051L  /* log_10 e */
-# define M_LN2l                0.6931471805599453094172321214581766L  /* log_e 2 */
-# define M_LN10l       2.3025850929940456840179914546843642 /* log_e 10 */
-# define M_PIl         3.1415926535897932384626433832795029L  /* pi */
-# define M_PI_2l       1.5707963267948966192313216916397514 /* pi/2 */
-# define M_PI_4l       0.7853981633974483096156608458198757 /* pi/4 */
-# define M_1_PIl       0.3183098861837906715377675267450287 /* 1/pi */
-# define M_2_PIl       0.6366197723675813430755350534900574 /* 2/pi */
-# define M_2_SQRTPIl   1.1283791670955125738961589031215452L  /* 2/sqrt(pi) */
-# define M_SQRT2l      1.4142135623730950488016887242096981L  /* sqrt(2) */
-# define M_SQRT1_2l    0.7071067811865475244008443621048490 /* 1/sqrt(2) */
+# define M_El          2.718281828459045235360287471352662498L /* e */
+# define M_LOG2El      1.442695040888963407359924681001892137L /* log_2 e */
+# define M_LOG10El     0.434294481903251827651128918916605082L /* log_10 e */
+# define M_LN2l                0.693147180559945309417232121458176568L /* log_e 2 */
+# define M_LN10l       2.302585092994045684017991454684364208L /* log_e 10 */
+# define M_PIl         3.141592653589793238462643383279502884L /* pi */
+# define M_PI_2l       1.570796326794896619231321691639751442L /* pi/2 */
+# define M_PI_4l       0.785398163397448309615660845819875721L /* pi/4 */
+# define M_1_PIl       0.318309886183790671537767526745028724L /* 1/pi */
+# define M_2_PIl       0.636619772367581343075535053490057448L /* 2/pi */
+# define M_2_SQRTPIl   1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
+# define M_SQRT2l      1.414213562373095048801688724209698079L /* sqrt(2) */
+# define M_SQRT1_2l    0.707106781186547524400844362104849039L /* 1/sqrt(2) */
 #endif
 
 
@@ -357,7 +407,7 @@ extern int matherr (struct exception *__exc);
 # define __NO_MATH_INLINES     1
 #endif
 
-#if __USE_ISOC99 && __GNUC_PREREQ(2,97)
+#if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
 /* ISO C99 defines some macros to compare number while taking care for
    unordered numbers.  Many FPUs provide special instructions to support
    these operations.  Generic support in GCC for these as builtins went
@@ -377,7 +427,13 @@ extern int matherr (struct exception *__exc);
 # include <bits/mathinline.h>
 #endif
 
-#if __USE_ISOC99
+/* Define special entry points to use when the compiler got told to
+   only expect finite results.  */
+#if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
+# include <bits/math-finite.h>
+#endif
+
+#ifdef __USE_ISOC99
 /* If we've still got undefined comparison macros, provide defaults.  */
 
 /* Return nonzero value if X is greater than Y.  */