gstpad: Fix non-serialized sticky event push
[platform/upstream/gstreamer.git] / subprojects / gstreamer / 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 #ifndef __GI_SCANNER__
24
25 /* This header is not included automatically via gst/gst.h, you need to
26  * include it explicitly if you need it. */
27
28 #ifndef _USE_MATH_DEFINES
29 #define _USE_MATH_DEFINES /* so MSVC defines M_PI etc. */
30 #endif
31 #include <math.h>
32
33 #include <glib.h>
34
35 G_BEGIN_DECLS
36
37 /* http://en.wikipedia.org/wiki/Math.h */
38
39 #define __GST_MATH_COMPAT_NEED_RINT
40 #define __GST_MATH_COMPAT_NEED_RINTF
41 #define __GST_MATH_COMPAT_NEED_ISNAN
42
43 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
44 #undef __GST_MATH_COMPAT_NEED_RINT
45 #undef __GST_MATH_COMPAT_NEED_RINTF
46 #undef __GST_MATH_COMPAT_NEED_ISNAN
47 #endif
48
49 #if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
50 #undef __GST_MATH_COMPAT_NEED_RINT
51 #undef __GST_MATH_COMPAT_NEED_RINTF
52 #undef __GST_MATH_COMPAT_NEED_ISNAN
53 #endif
54
55 #ifndef M_PI
56 #define M_PI G_PI
57 #endif
58
59 #ifndef M_PI_2
60 #define M_PI_2 G_PI_2
61 #endif
62
63 #ifndef M_PI_4
64 #define M_PI_4 G_PI_4
65 #endif
66
67 static inline double
68 __gst_math_compat_rint (double x)
69 {
70   return floor (x + 0.5);
71 }
72
73 static inline float
74 __gst_math_compat_rintf (float x)
75 {
76   return floorf (x + 0.5);
77 }
78
79 static inline gboolean
80 __gst_math_compat_isnan (double x)
81 {
82   return x != x;
83 }
84
85 #if defined (__GST_MATH_COMPAT_NEED_RINT) && !defined (rint)
86 #define rint(x) __gst_math_compat_rint(x)
87 #endif
88
89 #if defined (__GST_MATH_COMPAT_NEED_RINTF) && !defined (rintf)
90 #define rintf(x) __gst_math_compat_rintf(x)
91 #endif
92
93 #if defined (__GST_MATH_COMPAT_NEED_ISNAN) && !defined (isnan)
94 #define isnan(x) __gst_math_compat_isnan (x)
95 #endif
96
97 #ifndef NAN
98 #if G_BYTE_ORDER == G_BIG_ENDIAN
99 #define __GST_NAN_BYTES        { 0x7f, 0xc0, 0, 0 }
100 #elif G_BYTE_ORDER == G_LITTLE_ENDIAN
101 #define __GST_NAN_BYTES        { 0, 0, 0xc0, 0x7f }
102 #endif
103 static union {
104   unsigned char __c[4];
105   float __d;
106 } __gst_nan_union G_GNUC_UNUSED = {
107   __GST_NAN_BYTES
108 };
109 #define NAN    (__gst_nan_union.__d)
110 #endif
111
112 G_END_DECLS
113
114 #endif /* !__GI_SCANNER__ */
115
116 #endif /* __GST_MATH_COMPAT_H__ */