2010-10-05 13:16:19 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-10-05 13:16:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_MATH_COMPAT_H__
|
|
|
|
#define __GST_MATH_COMPAT_H__
|
|
|
|
|
|
|
|
/* This header is not included automatically via gst/gst.h, you need to
|
|
|
|
* include it explicitly if you need it. */
|
|
|
|
|
2010-11-03 14:21:02 +00:00
|
|
|
#ifndef _USE_MATH_DEFINES
|
2010-10-05 13:16:19 +00:00
|
|
|
#define _USE_MATH_DEFINES /* so MSVC defines M_PI etc. */
|
2010-11-03 14:21:02 +00:00
|
|
|
#endif
|
2010-10-05 13:16:19 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
/* http://en.wikipedia.org/wiki/Math.h */
|
|
|
|
|
|
|
|
#define __GST_MATH_COMPAT_NEED_RINT
|
|
|
|
#define __GST_MATH_COMPAT_NEED_RINTF
|
2012-06-29 08:52:31 +00:00
|
|
|
#define __GST_MATH_COMPAT_NEED_ISNAN
|
2010-10-05 13:16:19 +00:00
|
|
|
|
|
|
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
|
|
|
#undef __GST_MATH_COMPAT_NEED_RINT
|
|
|
|
#undef __GST_MATH_COMPAT_NEED_RINTF
|
2012-06-29 08:52:31 +00:00
|
|
|
#undef __GST_MATH_COMPAT_NEED_ISNAN
|
2010-10-05 13:16:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
|
|
|
|
#undef __GST_MATH_COMPAT_NEED_RINT
|
|
|
|
#undef __GST_MATH_COMPAT_NEED_RINTF
|
2012-06-29 08:52:31 +00:00
|
|
|
#undef __GST_MATH_COMPAT_NEED_ISNAN
|
2010-10-05 13:16:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI G_PI
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef M_PI_2
|
|
|
|
#define M_PI_2 G_PI_2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef M_PI_4
|
|
|
|
#define M_PI_4 G_PI_4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline double
|
|
|
|
__gst_math_compat_rint (double x)
|
|
|
|
{
|
|
|
|
return floor (x + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float
|
|
|
|
__gst_math_compat_rintf (float x)
|
|
|
|
{
|
|
|
|
return floorf (x + 0.5);
|
|
|
|
}
|
|
|
|
|
2012-06-29 08:52:31 +00:00
|
|
|
static inline gboolean
|
|
|
|
__gst_math_compat_isnan (double x)
|
|
|
|
{
|
|
|
|
return x != x;
|
|
|
|
}
|
|
|
|
|
2010-10-05 13:16:19 +00:00
|
|
|
#if defined (__GST_MATH_COMPAT_NEED_RINT) && !defined (rint)
|
|
|
|
#define rint(x) __gst_math_compat_rint(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (__GST_MATH_COMPAT_NEED_RINTF) && !defined (rintf)
|
|
|
|
#define rintf(x) __gst_math_compat_rintf(x)
|
|
|
|
#endif
|
|
|
|
|
2012-06-29 08:52:31 +00:00
|
|
|
#if defined (__GST_MATH_COMPAT_NEED_ISNAN) && !defined (isnan)
|
|
|
|
#define isnan(x) __gst_math_compat_isnan (x)
|
|
|
|
#endif
|
|
|
|
|
2011-12-30 12:59:46 +00:00
|
|
|
#ifndef NAN
|
2011-12-30 12:32:18 +00:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
2011-12-30 12:59:46 +00:00
|
|
|
#define __GST_NAN_BYTES { 0x7f, 0xc0, 0, 0 }
|
|
|
|
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
#define __GST_NAN_BYTES { 0, 0, 0xc0, 0x7f }
|
2011-12-30 12:32:18 +00:00
|
|
|
#endif
|
|
|
|
static union {
|
|
|
|
unsigned char __c[4];
|
|
|
|
float __d;
|
2011-12-30 12:59:46 +00:00
|
|
|
} __gst_nan_union G_GNUC_UNUSED = {
|
|
|
|
__GST_NAN_BYTES
|
2011-12-30 12:32:18 +00:00
|
|
|
};
|
|
|
|
#define NAN (__gst_nan_union.__d)
|
|
|
|
#endif
|
|
|
|
|
2010-10-05 13:16:19 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_MATH_COMPAT_H__ */
|