Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**************************************************************************
  2. *
  3. * Copyright 2007-2015 VMware, Inc.
  4. * All Rights Reserved.
  5. *
  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:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  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.
  25. *
  26. **************************************************************************/
  27. /**
  28. * Wrapper for math.h which makes sure we have definitions of all the c99
  29. * functions.
  30. */
  31. #ifndef _C99_MATH_H_
  32. #define _C99_MATH_H_
  33. #include <math.h>
  34. #include "c99_compat.h"
  35. /* This is to ensure that we get M_PI, etc. definitions */
  36. #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
  37. #error _USE_MATH_DEFINES define required when building with MSVC
  38. #endif
  39. #if !defined(_MSC_VER) && \
  40. __STDC_VERSION__ < 199901L && \
  41. (!defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 600) && \
  42. !defined(__cplusplus)
  43. static inline long int
  44. lrint(double d)
  45. {
  46. long int rounded = (long int)(d + 0.5);
  47. if (d - floor(d) == 0.5) {
  48. if (rounded % 2 != 0)
  49. rounded += (d > 0) ? -1 : 1;
  50. }
  51. return rounded;
  52. }
  53. static inline long int
  54. lrintf(float f)
  55. {
  56. long int rounded = (long int)(f + 0.5f);
  57. if (f - floorf(f) == 0.5f) {
  58. if (rounded % 2 != 0)
  59. rounded += (f > 0) ? -1 : 1;
  60. }
  61. return rounded;
  62. }
  63. static inline long long int
  64. llrint(double d)
  65. {
  66. long long int rounded = (long long int)(d + 0.5);
  67. if (d - floor(d) == 0.5) {
  68. if (rounded % 2 != 0)
  69. rounded += (d > 0) ? -1 : 1;
  70. }
  71. return rounded;
  72. }
  73. static inline long long int
  74. llrintf(float f)
  75. {
  76. long long int rounded = (long long int)(f + 0.5f);
  77. if (f - floorf(f) == 0.5f) {
  78. if (rounded % 2 != 0)
  79. rounded += (f > 0) ? -1 : 1;
  80. }
  81. return rounded;
  82. }
  83. static inline float
  84. exp2f(float f)
  85. {
  86. return powf(2.0f, f);
  87. }
  88. static inline double
  89. exp2(double d)
  90. {
  91. return pow(2.0, d);
  92. }
  93. #endif /* C99 */
  94. /*
  95. * signbit() is a macro on Linux. Not available on Windows.
  96. */
  97. #ifndef signbit
  98. #define signbit(x) ((x) < 0.0f)
  99. #endif
  100. #ifndef M_PI
  101. #define M_PI (3.14159265358979323846)
  102. #endif
  103. #ifndef M_E
  104. #define M_E (2.7182818284590452354)
  105. #endif
  106. #ifndef M_LOG2E
  107. #define M_LOG2E (1.4426950408889634074)
  108. #endif
  109. #ifndef FLT_MAX_EXP
  110. #define FLT_MAX_EXP 128
  111. #endif
  112. #if defined(fpclassify)
  113. /* ISO C99 says that fpclassify is a macro. Assume that any implementation
  114. * of fpclassify, whether it's in a C99 compiler or not, will be a macro.
  115. */
  116. #elif defined(__cplusplus)
  117. /* For C++, fpclassify() should be defined in <cmath> */
  118. #elif defined(_MSC_VER)
  119. /* Not required on VS2013 and above. Oddly, the fpclassify() function
  120. * doesn't exist in such a form on MSVC. This is an implementation using
  121. * slightly different lower-level Windows functions.
  122. */
  123. #include <float.h>
  124. static inline enum {FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_NORMAL}
  125. fpclassify(double x)
  126. {
  127. switch(_fpclass(x)) {
  128. case _FPCLASS_SNAN: /* signaling NaN */
  129. case _FPCLASS_QNAN: /* quiet NaN */
  130. return FP_NAN;
  131. case _FPCLASS_NINF: /* negative infinity */
  132. case _FPCLASS_PINF: /* positive infinity */
  133. return FP_INFINITE;
  134. case _FPCLASS_NN: /* negative normal */
  135. case _FPCLASS_PN: /* positive normal */
  136. return FP_NORMAL;
  137. case _FPCLASS_ND: /* negative denormalized */
  138. case _FPCLASS_PD: /* positive denormalized */
  139. return FP_SUBNORMAL;
  140. case _FPCLASS_NZ: /* negative zero */
  141. case _FPCLASS_PZ: /* positive zero */
  142. return FP_ZERO;
  143. default:
  144. /* Should never get here; but if we do, this will guarantee
  145. * that the pattern is not treated like a number.
  146. */
  147. return FP_NAN;
  148. }
  149. }
  150. #else
  151. #error "Need to include or define an fpclassify function"
  152. #endif
  153. /* Since C++11, the following functions are part of the std namespace. Their C
  154. * counteparts should still exist in the global namespace, however cmath
  155. * undefines those functions, which in glibc 2.23, are defined as macros rather
  156. * than functions as in glibc 2.22.
  157. */
  158. #if __cplusplus >= 201103L && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23))
  159. #include <cmath>
  160. using std::fpclassify;
  161. using std::isfinite;
  162. using std::isinf;
  163. using std::isnan;
  164. using std::isnormal;
  165. using std::signbit;
  166. using std::isgreater;
  167. using std::isgreaterequal;
  168. using std::isless;
  169. using std::islessequal;
  170. using std::islessgreater;
  171. using std::isunordered;
  172. #endif
  173. #endif /* #define _C99_MATH_H_ */