meta: Use _mesa_NamedBufferData and _mesa_NamedBufferSubData for users of _mesa_meta_...
[mesa.git] / include / c99_math.h
index 35173c68d1c0637c90961f392dc488672d1aae2d..8a67fb133d6e26013c0e5be8e5d84d33d0a5b5e9 100644 (file)
@@ -71,6 +71,7 @@ roundf(float x)
 #endif
 
 #ifndef INFINITY
+#include <float.h> // DBL_MAX
 #define INFINITY (DBL_MAX + DBL_MAX)
 #endif
 
@@ -81,7 +82,12 @@ roundf(float x)
 #endif /* _MSC_VER */
 
 
-#if __STDC_VERSION__ < 199901L && (!defined(__cplusplus) || defined(_MSC_VER))
+#if (defined(_MSC_VER) && _MSC_VER < 1800) || \
+    (!defined(_MSC_VER) && \
+     __STDC_VERSION__ < 199901L && \
+     (!defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 600) && \
+     !defined(__cplusplus))
+
 static inline long int
 lrint(double d)
 {
@@ -133,6 +139,19 @@ llrintf(float f)
 
    return rounded;
 }
+
+static inline float
+exp2f(float f)
+{
+   return powf(2.0f, f);
+}
+
+static inline double
+exp2(double d)
+{
+   return pow(2.0, d);
+}
+
 #endif /* C99 */
 
 
@@ -156,5 +175,53 @@ llrintf(float f)
 #define M_LOG2E (1.4426950408889634074)
 #endif
 
+#ifndef FLT_MAX_EXP
+#define FLT_MAX_EXP 128
+#endif
+
+
+#if defined(fpclassify)
+/* ISO C99 says that fpclassify is a macro.  Assume that any implementation
+ * of fpclassify, whether it's in a C99 compiler or not, will be a macro.
+ */
+#elif defined(__cplusplus)
+/* For C++, fpclassify() should be defined in <cmath> */
+#elif defined(_MSC_VER)
+/* Not required on VS2013 and above.  Oddly, the fpclassify() function
+ * doesn't exist in such a form on MSVC.  This is an implementation using
+ * slightly different lower-level Windows functions.
+ */
+#include <float.h>
+
+static inline enum {FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_NORMAL}
+fpclassify(double x)
+{
+   switch(_fpclass(x)) {
+   case _FPCLASS_SNAN: /* signaling NaN */
+   case _FPCLASS_QNAN: /* quiet NaN */
+      return FP_NAN;
+   case _FPCLASS_NINF: /* negative infinity */
+   case _FPCLASS_PINF: /* positive infinity */
+      return FP_INFINITE;
+   case _FPCLASS_NN:   /* negative normal */
+   case _FPCLASS_PN:   /* positive normal */
+      return FP_NORMAL;
+   case _FPCLASS_ND:   /* negative denormalized */
+   case _FPCLASS_PD:   /* positive denormalized */
+      return FP_SUBNORMAL;
+   case _FPCLASS_NZ:   /* negative zero */
+   case _FPCLASS_PZ:   /* positive zero */
+      return FP_ZERO;
+   default:
+      /* Should never get here; but if we do, this will guarantee
+       * that the pattern is not treated like a number.
+       */
+      return FP_NAN;
+   }
+}
+#else
+#error "Need to include or define an fpclassify function"
+#endif
+
 
 #endif /* #define _C99_MATH_H_ */