2
** Copyright (C) 2001-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU Lesser General Public License as published by
6
** the Free Software Foundation; either version 2.1 of the License, or
7
** (at your option) any later version.
9
** This program 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
12
** GNU Lesser General Public License for more details.
14
** You should have received a copy of the GNU Lesser General Public License
15
** along with this program; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#ifndef FLOAT_CAST_HEADER
22
#define FLOAT_CAST_HEADER
24
/*============================================================================
25
** On Intel Pentium processors (especially PIII and probably P4), converting
26
** from float to int is very slow. To meet the C specs, the code produced by
27
** most C compilers targeting Pentium needs to change the FPU rounding mode
28
** before the float to int conversion is performed.
30
** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
31
** is this flushing of the pipeline which is so slow.
33
** Fortunately the ISO C99 specifications define the functions lrint, lrintf,
34
** llrint and llrintf which fix this problem as a side effect.
36
** On Unix-like systems, the configure process should have detected the
37
** presence of these functions. If they weren't found we have to replace them
38
** here with a standard C cast.
42
** The C99 prototypes for lrint and lrintf are as follows:
44
** long int lrintf (float x) ;
45
** long int lrint (double x) ;
51
** The presence of the required functions are detected during the configure
52
** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
53
** the sfconfig.h file.
56
#define HAVE_LRINT_REPLACEMENT 0
58
#if (HAVE_LRINT && HAVE_LRINTF)
61
** These defines enable functionality introduced with the 1999 ISO C
62
** standard. They must be defined before the inclusion of math.h to
63
** engage them. If optimisation is enabled, these functions will be
64
** inlined. With optimisation switched off, you have to link in the
65
** maths library using -lm.
68
#define _ISOC9X_SOURCE 1
69
#define _ISOC99_SOURCE 1
71
#define __USE_ISOC9X 1
72
#define __USE_ISOC99 1
76
#elif (defined (__CYGWIN__))
80
#undef HAVE_LRINT_REPLACEMENT
81
#define HAVE_LRINT_REPLACEMENT 1
86
#define lrint double2int
87
#define lrintf float2int
90
** The native CYGWIN lrint and lrintf functions are buggy:
91
** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
92
** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
94
** These functions (pulled from the Public Domain MinGW math.h header)
95
** replace the native versions.
98
static inline long double2int (double in)
111
static inline long float2int (float in)
124
#elif (defined (WIN32) || defined (_WIN32))
126
#undef HAVE_LRINT_REPLACEMENT
127
#define HAVE_LRINT_REPLACEMENT 1
132
** Win32 doesn't seem to have these functions.
133
** Therefore implement inline versions of these functions here.
160
#elif (defined (__MWERKS__) && defined (macintosh))
162
/* This MacOS 9 solution was provided by Stephane Letz */
164
#undef HAVE_LRINT_REPLACEMENT
165
#define HAVE_LRINT_REPLACEMENT 1
171
#define lrint double2int
172
#define lrintf float2int
175
float2int (register float in)
186
double2int (register double in)
196
#elif (defined (__MACH__) && defined (__APPLE__))
198
/* For Apple MacOSX. */
200
#undef HAVE_LRINT_REPLACEMENT
201
#define HAVE_LRINT_REPLACEMENT 1
207
#define lrint double2int
208
#define lrintf float2int
211
float2int (register float in)
217
: "=m" (res) /* Output */
218
: "f" (in) /* Input */
226
double2int (register double in)
232
: "=m" (res) /* Output */
233
: "f" (in) /* Input */
242
#warning "Don't have the functions lrint() and lrintf()."
243
#warning "Replacing these functions with a standard C cast."
248
#define lrint(dbl) ((long) (dbl))
249
#define lrintf(flt) ((long) (flt))
254
#endif /* FLOAT_CAST_HEADER */
257
** Do not edit or modify anything in this comment block.
258
** The arch-tag line is a file identity tag for the GNU Arch
259
** revision control system.
261
** arch-tag: 42db1693-ff61-4051-bac1-e4d24c4e30b7