-// ----------------------------------------------------------------------------
-// $Id$
-// ----------------------------------------------------------------------------
-// Public Domain C Library - http://pdclib.sourceforge.net
-// This code is Public Domain. Use, modify, and redistribute at will.
-// ----------------------------------------------------------------------------
-// Mathematics
-// ----------------------------------------------------------------------------
-
-#ifndef __MATH_H
-#define __MATH_H __MATH_H
-
-// TODO: Documentation
-
-// ----------------------------------------------------------------------------
-// DEFINES
-
-#define HUGE_VAL // TODO - personality?
-#define HUGE_VALF // TODO - personality?
-#define HUGE_VALL // TODO - personality?
-
-#define INFINITY // TODO - personality?
-#define NAN // TODO - personality?
-
-#define FP_FAST_FMA // TODO - personality?
-#define FP_FAST_FMAF // TODO - personality?
-#define FP_FAST_FMAL // TODO - personality?
-
-#define FP_INFINITE // TODO - personality?
-#define FP_NAN // TODO - personality?
-#define FP_NORMAL // TODO - personality?
-#define FP_SUBNORMAL // TODO - personality?
-#define FP_ZERO // TODO - personality?
-
-#define FP_ILOGB0 // TODO - personality?
-#define FP_ILOGBNAN // TODO - personality?
-
-#define MATH_ERRNO 1 // personality?
-#define MATH_ERREXCEPT 2 // personality?
-#define math_errhandling // TODO - personality?
-
-// --------------------------------------------------------------------------
-// TYPEDEFS
-
-typedef double_t; // TODO - personality?
-typedef float_t; // TODO - personality?
-
-// --------------------------------------------------------------------------
-// MACROS
-
-#define isgreater( x, y ) // TODO
-#define isgreaterequal( x, y ) // TODO
-#define isless( x, y ) // TODO
-#define islessequal( x, y ) // TODO
-#define islessgreater( x, y ) // TODO
-#define isunordered( x, y ) // TODO
-#define fpclassify( x ) // TODO
-#define isfinite( x ) // TODO
-
-#define isinf( x ) // TODO
-#define isnan( x ) // TODO
-#define isnormal( x ) // TODO
-#define signbit( x ) // TODO
-
-// ----------------------------------------------------------------------------
-// FUNCTIONS
-
-// These functions return the magnitude of their parameter.
+/* ----------------------------------------------------------------------------
+ * $Id$
+ * ----------------------------------------------------------------------------
+ * Public Domain C Library - http://pdclib.sourceforge.net
+ * This code is Public Domain. Use, modify, and redistribute at will.
+ * ----------------------------------------------------------------------------
+ * Mathematics
+ * --------------------------------------------------------------------------*/
+
+#ifndef _MATH_H
+#define _MATH_H _MATH_H
+
+/* TODO: Documentation */
+
+/* ----------------------------------------------------------------------------
+ * DEFINES
+ * --------------------------------------------------------------------------*/
+
+#define HUGE_VAL ((double)0x7FF0000000000000) /* TODO */
+#define HUGE_VALF ((float)0x7F800000) /* TODO */
+#define HUGE_VALL ((long double)0x7FFF8000000000000000) /* TODO */
+
+#define INFINITY ((float)0x7F800000) /* TODO */
+#define NAN ((float)0x7F800001) /* TODO */
+
+/* The following values are platform dependant, must be personality. */
+#if 0
+#define FP_FAST_FMA /* TODO */
+#define FP_FAST_FMAF /* TODO */
+#define FP_FAST_FMAL /* TODO */
+#endif
+
+/* These values are used instead of constants to classify numbers. */
+#define FP_UNDEFINED 0
+#define FP_INFINITE 1
+#define FP_NAN 2
+#define FP_NORMAL 3
+#define FP_SUBNORMAL 4
+#define FP_ZERO 5
+
+#define FP_ILOGB0 /* TODO */
+#define FP_ILOGBNAN /* TODO */
+
+#define MATH_ERRNO 1
+#define MATH_ERREXCEPT 2
+
+/* should be MATH_ERRNO | MATH_ERREXCEPT if we do exceptions. Do we? It's
+ * nice if this is implementation-wide the same.
+ */
+#define math_errhandling ((int)MATH_ERRNO)
+
+/* ----------------------------------------------------------------------------
+ * TYPEDEFS
+ * --------------------------------------------------------------------------*/
+
+typedef double_t
+#if FLT_EVAL_METHOD == 0
+ double
+#elif FLT_EVAL_METHOD == 1
+ double
+#elif FLT_EVAL_METHOD == 2
+ long double
+#else
+ /* TODO - this is implementation defined and cpu dependant */
+#endif
+;
+
+typedef float_t
+#if FLT_EVAL_METHOD == 0
+ float
+#elif FLT_EVAL_METHOD == 1
+ double
+#elif FLT_EVAL_METHOD == 2
+ long double
+#else
+ /* TODO - this is implementation defined and cpu dependant */
+#endif
+;
+
+/* ----------------------------------------------------------------------------
+ * MACROS
+ * --------------------------------------------------------------------------*/
+
+#define isgreater( x, y ) /* TODO */
+#define isgreaterequal( x, y ) /* TODO */
+#define isless( x, y ) /* TODO */
+#define islessequal( x, y ) /* TODO */
+#define islessgreater( x, y ) /* TODO */
+#define isunordered( x, y ) /* TODO */
+
+/* Could somebody clean this macro up? It uses 7 other definitions (below).
+ * Also, I suspect this macro to be personality-dependant. Somebody confirm
+ * or deny?
+ */
+#define fp_mef 0x7F800000
+#define fp_mff 0x007FFFFF
+#define fp_med 0x7FF0000000000000
+#define fp_mfd 0x000FFFFFFFFFFFFF
+#define fp_mel 0x7FFF8000000000000000
+#define fp_mjl 0x00004000000000000000 // the j-bit mask
+#define fp_mfl 0x00003FFFFFFFFFFFFFFF
+
+#define fpclassify( x ) ((sizeof(x) == sizeof(float)) ? ( \
+ (((x) & fp_mef) == (fp_mef)) ? ( \
+ (((x) & fp_mff) == (0)) ? ( \
+ FP_INFINITY \
+ ) : ( \
+ FP_NAN \
+ ) \
+ ) : ( \
+ (((x) & fp_mef) == (0)) ? ( \
+ (((x) & fp_mff) == (0)) ? ( \
+ FP_ZERO \
+ ) : ( \
+ FP_DENORMAL \
+ ) \
+ ) : ( \
+ FP_NORMAL \
+ ) \
+ ) \
+ ) : (
+ (sizeof(x) == sizeof(double)) ? ( \
+ (((x) & fp_med) == (fp_med)) ? ( \
+ (((x) & fp_mfd) == (0)) ? ( \
+ FP_INFINITY \
+ ) : ( \
+ FP_NAN \
+ ) \
+ ) : ( \
+ (((x) & fp_med) == (0)) ? ( \
+ (((x) & fp_mfd) == (0)) ? ( \
+ FP_ZERO \
+ ) : ( \
+ FP_DENORMAL \
+ ) \
+ ) : ( \
+ FP_NORMAL \
+ ) \
+ ) \
+ ) : ( \
+ (((x) & fp_mel) == (fp_mel)) ? ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ FP_UNSUPPORTED \
+ ) : ( \
+ (((x) & fp_mfl) == (fp_mfl)) ? ( \
+ FP_NAN \
+ ) : ( \
+ FP_INFINITY \
+ ) \
+ ) \
+ ) : ( \
+ (((x) & fp_mel) == (0)) ? ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ FP_NORMAL \ // or actually, pseudo-denormal
+ ) : ( \
+ (((x) & fp_mfl) == (fp_mfl)) ? ( \
+ FP_DENORMAL \
+ ) : ( \
+ FP_ZERO \
+ ) \
+ ) \
+ ) : ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ FP_NORMAL \
+ ) : ( \
+ FP_UNDEFINED \
+ ) \
+ ) \
+ ) \
+ ) \
+ ) \
+ )
+
+#define isfinite( x ) ((sizeof(x) == sizeof(float)) ? ( \
+ (((x) & fp_mef) == (fp_mef)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : (
+ (sizeof(x) == sizeof(double)) ? ( \
+ (((x) & fp_med) == (fp_med)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : ( \
+ (((x) & fp_mel) == (fp_mel)) ? ( \
+ 0 \
+ ) : ( \
+ (((x) & fp_mel) == (0)) ? ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) \
+ ) \
+ ) \
+ ) \
+ )
+
+#define isinf( x ) ((sizeof(x) == sizeof(float)) ? ( \
+ (((x) & fp_mef) == (fp_mef)) ? ( \
+ (((x) & fp_mff) == (0)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ((sizeof(x) == sizeof(double)) ? ( \
+ (((x) & fp_med) == (fp_med)) ? ( \
+ (((x) & fp_mfd) == (0)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ (((x) & fp_mel) == (fp_mel)) ? ( \
+ (((x) & fp_mjl) == (0)) ? ( \
+ (((x) & fp_mfl) == (fp_mfl)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) \
+ ) \
+ )
+
+#define isnan( x ) ((sizeof(x) == sizeof(float)) ? ( \
+ (((x) & fp_mef) == (fp_mef)) ? ( \
+ (((x) & fp_mff) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ((sizeof(x) == sizeof(double)) ? ( \
+ (((x) & fp_med) == (fp_med)) ? ( \
+ (((x) & fp_mfd) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ (((x) & fp_mel) == (fp_mel)) ? ( \
+ (((x) & fp_mjl) == (0)) ? ( \
+ (((x) & fp_mfl) == (fp_mfl)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ 0 \
+ ) \
+ ) \
+ ) \
+ )
+
+#define isnormal( x ) ((sizeof(x) == sizeof(float)) ? ( \
+ (((x) & fp_mef) == (fp_mef)) ? ( \
+ 0 \
+ ) : ( \
+ (((x) & fp_mef) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) \
+ ) : ((sizeof(x) == sizeof(double)) ? ( \
+ (((x) & fp_med) == (fp_med)) ? ( \
+ 0 \
+ ) : ( \
+ (((x) & fp_med) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) \
+ ) : ( \
+ (((x) & fp_mel) == (fp_mel)) ? ( \
+ 0 \
+ ) : ( \
+ (((x) & fp_mel) == (0)) ? ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) : ( \
+ (((x) & fp_mjl) == (fp_mjl)) ? ( \
+ 1 \
+ ) : ( \
+ 0 \
+ ) \
+ ) \
+ ) \
+ ) \
+ ) \
+ )
+
+#define signbit( x ) ((sizeof(x) == sizeof(float)) ? ( \
+ (((x) & 0x80000000) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : ((sizeof(x) == sizeof(double)) ? ( \
+ (((x) & 0x8000000000000000) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) : ( \
+ (((x) & 0x80000000000000000000) == (0)) ? ( \
+ 0 \
+ ) : ( \
+ 1 \
+ ) \
+ ) \
+ ) \
+ )
+
+/* ----------------------------------------------------------------------------
+ * FUNCTIONS
+ * --------------------------------------------------------------------------*/
+
+/** These functions return the magnitude of x.
+ * @param x The value to find the absolute value of.
+ * @return The absolute value of x.
+ * @see fabsl()
+ * @see fabsf()
+ */