tee: Check for the removed pad flag also in the slow pushing path
[platform/upstream/gstreamer.git] / gst / math-compat.h
1 /* GStreamer
2  * Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef __GST_MATH_COMPAT_H__
21 #define __GST_MATH_COMPAT_H__
22
23 /* This header is not included automatically via gst/gst.h, you need to
24  * include it explicitly if you need it. */
25
26 #ifndef _USE_MATH_DEFINES
27 #define _USE_MATH_DEFINES /* so MSVC defines M_PI etc. */
28 #endif
29 #include <math.h>
30
31 #include <glib.h>
32
33 G_BEGIN_DECLS
34
35 /* http://en.wikipedia.org/wiki/Math.h */
36
37 #define __GST_MATH_COMPAT_NEED_RINT
38 #define __GST_MATH_COMPAT_NEED_RINTF
39 #define __GST_MATH_COMPAT_NEED_ISNAN
40
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
45 #endif
46
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
51 #endif
52
53 #ifndef M_PI
54 #define M_PI G_PI
55 #endif
56
57 #ifndef M_PI_2
58 #define M_PI_2 G_PI_2
59 #endif
60
61 #ifndef M_PI_4
62 #define M_PI_4 G_PI_4
63 #endif
64
65 static inline double
66 __gst_math_compat_rint (double x)
67 {
68   return floor (x + 0.5);
69 }
70
71 static inline float
72 __gst_math_compat_rintf (float x)
73 {
74   return floorf (x + 0.5);
75 }
76
77 static inline gboolean
78 __gst_math_compat_isnan (double x)
79 {
80   return x != x;
81 }
82
83 #if defined (__GST_MATH_COMPAT_NEED_RINT) && !defined (rint)
84 #define rint(x) __gst_math_compat_rint(x)
85 #endif
86
87 #if defined (__GST_MATH_COMPAT_NEED_RINTF) && !defined (rintf)
88 #define rintf(x) __gst_math_compat_rintf(x)
89 #endif
90
91 #if defined (__GST_MATH_COMPAT_NEED_ISNAN) && !defined (isnan)
92 #define isnan(x) __gst_math_compat_isnan (x)
93 #endif
94
95 #ifndef NAN
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 }
100 #endif
101 static union {
102   unsigned char __c[4];
103   float __d;
104 } __gst_nan_union G_GNUC_UNUSED = {
105   __GST_NAN_BYTES
106 };
107 #define NAN    (__gst_nan_union.__d)
108 #endif
109
110 G_END_DECLS
111
112 #endif /* __GST_MATH_COMPAT_H__ */