History

float_cast.h : Update to include Cygwin specific fixes.

Erik de Castro Lopo committed 21 years ago

Commit 07411551 parent ace89ad1 file · +61 −9Browse files

Unified · Split

src/float_cast.h+61−9
@@ -1,23 +1,25 @@
1/*1/*
2** Copyright (C) 2001-2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2001-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU Lesser General Public License as published by
6** the Free Software Foundation; either version 2 of the License, or6** the Free Software Foundation; either version 2.1 of the License, or
7** (at your option) any later version.7** (at your option) any later version.
8**8**
9** This program is distributed in the hope that it will be useful,9** This program is distributed in the hope that it will be useful,
10** but WITHOUT ANY WARRANTY; without even the implied warranty of10** but WITHOUT ANY WARRANTY; without even the implied warranty of
11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12** GNU General Public License for more details.12** GNU Lesser General Public License for more details.
13**13**
14** You should have received a copy of the GNU General Public License14** You should have received a copy of the GNU Lesser General Public License
15** along with this program; if not, write to the Free Software15** along with this program; if not, write to the Free Software
16** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.16** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/17*/
18 18
19/* Version 1.3 */19/* Version 1.4 */
20 20
21#ifndef FLOAT_CAST_HEADER
22#define FLOAT_CAST_HEADER
21 23
22/*============================================================================24/*============================================================================
23** On Intel Pentium processors (especially PIII and probably P4), converting25** On Intel Pentium processors (especially PIII and probably P4), converting
@@ -71,10 +73,59 @@ · 47 unmodified lines
71 73
72 #include <math.h>74 #include <math.h>
73 75
76#elif (defined (__CYGWIN__))
77
78 #include <math.h>
79
80 #undef HAVE_LRINT_REPLACEMENT
81 #define HAVE_LRINT_REPLACEMENT 1
82
83 #undef lrint
84 #undef lrintf
85
86 #define lrint double2int
87 #define lrintf float2int
88
89 /*
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
93 ** and slow.
94 ** These functions (pulled from the Public Domain MinGW math.h header)
95 ** replace the native versions.
96 */
97
98 static inline long double2int (double in)
99 { long retval ;
100
101 __asm__ __volatile__
102 ( "fistpl %0"
103 : "=m" (retval)
104 : "t" (in)
105 : "st"
106 ) ;
107
108 return retval ;
109 } /* double2int */
110
111 static inline long float2int (float in)
112 { long retval ;
113
114 __asm__ __volatile__
115 ( "fistpl %0"
116 : "=m" (retval)
117 : "t" (in)
118 : "st"
119 ) ;
120
121 return retval ;
122 } /* float2int */
123
74#elif (defined (WIN32) || defined (_WIN32))124#elif (defined (WIN32) || defined (_WIN32))
75 125
76 #undef HAVE_LRINT_REPLACEMENT126 #undef HAVE_LRINT_REPLACEMENT
77 #define HAVE_LRINT_REPLACEMENT 1127 #define HAVE_LRINT_REPLACEMENT 1
128
78 #include <math.h>129 #include <math.h>
79 130
80 /*131 /*
@@ -156,7 +207,7 @@ · 75 unmodified lines
156 #define lrint double2int207 #define lrint double2int
157 #define lrintf float2int208 #define lrintf float2int
158 209
159 inline static long int210 inline static long
160 float2int (register float in)211 float2int (register float in)
161 { int res [2] ;212 { int res [2] ;
162 213
@@ -171,7 +222,7 @@ · 8 unmodified lines
171 return res [1] ;222 return res [1] ;
172 } /* lrintf */223 } /* lrintf */
173 224
174 inline static long int225 inline static long
175 double2int (register double in)226 double2int (register double in)
176 { int res [2] ;227 { int res [2] ;
177 228
@@ -200,6 +251,7 @@ · 22 unmodified lines
200#endif251#endif
201 252
202 253
254#endif /* FLOAT_CAST_HEADER */
203 255
204/*256/*
205** Do not edit or modify anything in this comment block.257** Do not edit or modify anything in this comment block.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t