2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Library <2002> Steve Baker <stevebaker_org@yahoo.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:gstfloatcast
23 * @short_description: Floating point platform independence macros
25 * The floatcast.h header file contains a couple of convenience macros for
26 * floating point numbers.
28 * If you include this header, your application or library must link against
29 * libm (for maths.h support).
31 * For optimal results, your application's or library's build
32 * system should check whether the C99 functions lrint and lrintf are supported
33 * and define the preprocessor symbols HAVE_LRINT and HAVE_LRINTF if so. If
34 * you are using autoconf, you can do this by using the AC_C99_FUNC_LRINT and
35 * AC_C99_FUNC_LRINTF checks in your configure.ac or configure.in file and
36 * including your application's config.h header before you include floatcast.h.
39 #ifndef __FLOATCAST_H__
40 #define __FLOATCAST_H__
45 #if defined (_MSC_VER) && !defined (inline)
46 #define inline __inline
51 /* FIXME 0.11: these gst_cast_*() functions are not used anywhere, so we could
52 * just as well get rid of them and move the float/double swap macros into
53 * gstutils.h in core */
59 * Casts a 32-bit floating point value (float) to an integer without bias.
65 * Casts a 64-bit floating point value (double) to an integer without bias.
68 /* FIXME: HAVE_LRINT && HAVE_LRINTF are defined by config.h - they should
69 * not be used in an installed header. */
70 #if defined(HAVE_LRINT) && defined(HAVE_LRINTF)
72 /* These defines enable functionality introduced with the 1999 ISO C
73 ** standard. They must be defined before the inclusion of math.h to
74 ** engage them. If optimisation is enabled, these functions will be
75 ** inlined. With optimisation switched off, you have to link in the
76 ** maths library using -lm.
79 #define _ISOC9X_SOURCE 1
80 #define _ISOC99_SOURCE 1
82 #define __USE_ISOC9X 1
83 #define __USE_ISOC99 1
87 #define gst_cast_float(x) ((gint)lrintf(x))
88 #define gst_cast_double(x) ((gint)lrint(x))
93 /* use a standard c cast, but do rounding correctly */
94 #define gst_cast_float(x) ((gint)floor((x)+0.5))
95 #define gst_cast_double(x) ((gint)floor((x)+0.5))
101 #endif /* __FLOATCAST_H__ */