0a359ebb7628224dd911c8517f3b5e462edc0dbe
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 /* This is to ensure that we get M_PI, etc. definitions */
44 #if !defined(_USE_MATH_DEFINES)
45 #error _USE_MATH_DEFINES define required when building with MSVC
49 #define isfinite(x) _finite((double)(x))
50 #define isnan(x) _isnan((double)(x))
51 #endif /* _MSC_VER < 1800 */
54 static inline double log2( double x
)
56 const double invln2
= 1.442695041;
57 return log( x
) * invln2
;
63 return x
>= 0.0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
69 return x
>= 0.0f
? floorf(x
+ 0.5f
) : ceilf(x
- 0.5f
);
74 #define INFINITY (DBL_MAX + DBL_MAX)
78 #define NAN (INFINITY - INFINITY)
84 #if __STDC_VERSION__ < 199901L && (!defined(__cplusplus) || defined(_MSC_VER))
85 static inline long int
88 long int rounded
= (long int)(d
+ 0.5);
90 if (d
- floor(d
) == 0.5) {
92 rounded
+= (d
> 0) ? -1 : 1;
98 static inline long int
101 long int rounded
= (long int)(f
+ 0.5f
);
103 if (f
- floorf(f
) == 0.5f
) {
104 if (rounded
% 2 != 0)
105 rounded
+= (f
> 0) ? -1 : 1;
111 static inline long long int
114 long long int rounded
= (long long int)(d
+ 0.5);
116 if (d
- floor(d
) == 0.5) {
117 if (rounded
% 2 != 0)
118 rounded
+= (d
> 0) ? -1 : 1;
124 static inline long long int
127 long long int rounded
= (long long int)(f
+ 0.5f
);
129 if (f
- floorf(f
) == 0.5f
) {
130 if (rounded
% 2 != 0)
131 rounded
+= (f
> 0) ? -1 : 1;
140 * signbit() is a macro on Linux. Not available on Windows.
143 #define signbit(x) ((x) < 0.0f)
147 #endif /* #define _C99_MATH_H_ */