1 /**************************************************************************
3 * Copyright 2007-2015 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * Wrapper for math.h which makes sure we have definitions of all the c99
38 #include "c99_compat.h"
43 #if _MSC_VER < 1400 && !defined(__cplusplus)
45 static inline float cosf( float f
)
47 return (float) cos( (double) f
);
50 static inline float sinf( float f
)
52 return (float) sin( (double) f
);
55 static inline float ceilf( float f
)
57 return (float) ceil( (double) f
);
60 static inline float floorf( float f
)
62 return (float) floor( (double) f
);
65 static inline float powf( float f
, float g
)
67 return (float) pow( (double) f
, (double) g
);
70 static inline float sqrtf( float f
)
72 return (float) sqrt( (double) f
);
75 static inline float fabsf( float f
)
77 return (float) fabs( (double) f
);
80 static inline float logf( float f
)
82 return (float) log( (double) f
);
85 static inline float frexpf(float x
, int *exp
)
87 return (float) frexp(x
, exp
);
90 static inline float ldexpf(float x
, int exp
)
92 return (float) ldexp(x
, exp
);
95 static inline float logf(float x
)
97 return (float) log(x
);
100 static inline float expf(float x
)
102 return (float) exp(x
);
107 /* Work-around an extra semi-colon in VS 2005 logf definition */
110 #define logf(x) ((float)log((double)(x)))
114 #define isfinite(x) _finite((double)(x))
115 #define isnan(x) _isnan((double)(x))
116 #endif /* _MSC_VER < 1800 */
117 #endif /* _MSC_VER < 1400 && !defined(__cplusplus) */
120 static inline double log2( double x
)
122 const double invln2
= 1.442695041;
123 return log( x
) * invln2
;
129 return x
>= 0.0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
135 return x
>= 0.0f
? floorf(x
+ 0.5f
) : ceilf(x
- 0.5f
);
140 #define INFINITY (DBL_MAX + DBL_MAX)
144 #define NAN (INFINITY - INFINITY)
147 #endif /* _MSC_VER */
150 #if __STDC_VERSION__ < 199901L && (!defined(__cplusplus) || defined(_MSC_VER))
151 static inline long int
154 long int rounded
= (long int)(d
+ 0.5);
156 if (d
- floor(d
) == 0.5) {
157 if (rounded
% 2 != 0)
158 rounded
+= (d
> 0) ? -1 : 1;
164 static inline long int
167 long int rounded
= (long int)(f
+ 0.5f
);
169 if (f
- floorf(f
) == 0.5f
) {
170 if (rounded
% 2 != 0)
171 rounded
+= (f
> 0) ? -1 : 1;
177 static inline long long int
180 long long int rounded
= (long long int)(d
+ 0.5);
182 if (d
- floor(d
) == 0.5) {
183 if (rounded
% 2 != 0)
184 rounded
+= (d
> 0) ? -1 : 1;
190 static inline long long int
193 long long int rounded
= (long long int)(f
+ 0.5f
);
195 if (f
- floorf(f
) == 0.5f
) {
196 if (rounded
% 2 != 0)
197 rounded
+= (f
> 0) ? -1 : 1;
205 #endif /* #define _C99_MATH_H_ */