2 * Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef __GST_MATH_COMPAT_H__
21 #define __GST_MATH_COMPAT_H__
23 /* This header is not included automatically via gst/gst.h, you need to
24 * include it explicitly if you need it. */
26 #ifndef _USE_MATH_DEFINES
27 #define _USE_MATH_DEFINES /* so MSVC defines M_PI etc. */
35 /* http://en.wikipedia.org/wiki/Math.h */
37 #define __GST_MATH_COMPAT_NEED_RINT
38 #define __GST_MATH_COMPAT_NEED_RINTF
39 #define __GST_MATH_COMPAT_NEED_ISNAN
41 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
42 #undef __GST_MATH_COMPAT_NEED_RINT
43 #undef __GST_MATH_COMPAT_NEED_RINTF
44 #undef __GST_MATH_COMPAT_NEED_ISNAN
47 #if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
48 #undef __GST_MATH_COMPAT_NEED_RINT
49 #undef __GST_MATH_COMPAT_NEED_RINTF
50 #undef __GST_MATH_COMPAT_NEED_ISNAN
66 __gst_math_compat_rint (double x)
68 return floor (x + 0.5);
72 __gst_math_compat_rintf (float x)
74 return floorf (x + 0.5);
77 static inline gboolean
78 __gst_math_compat_isnan (double x)
83 #if defined (__GST_MATH_COMPAT_NEED_RINT) && !defined (rint)
84 #define rint(x) __gst_math_compat_rint(x)
87 #if defined (__GST_MATH_COMPAT_NEED_RINTF) && !defined (rintf)
88 #define rintf(x) __gst_math_compat_rintf(x)
91 #if defined (__GST_MATH_COMPAT_NEED_ISNAN) && !defined (isnan)
92 #define isnan(x) __gst_math_compat_isnan (x)
96 #if G_BYTE_ORDER == G_BIG_ENDIAN
97 #define __GST_NAN_BYTES { 0x7f, 0xc0, 0, 0 }
98 #elif G_BYTE_ORDER == G_LITTLE_ENDIAN
99 #define __GST_NAN_BYTES { 0, 0, 0xc0, 0x7f }
102 unsigned char __c[4];
104 } __gst_nan_union G_GNUC_UNUSED = {
107 #define NAN (__gst_nan_union.__d)
112 #endif /* __GST_MATH_COMPAT_H__ */