Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

150 рядки
4.0 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. //
  11. // The Real class
  12. // --------------
  13. //
  14. #if !defined __LOL_REAL_H__
  15. #define __LOL_REAL_H__
  16. #include <stdint.h>
  17. /* Avoid issues with NaCl headers */
  18. #undef log2
  19. namespace lol
  20. {
  21. class real
  22. {
  23. public:
  24. real();
  25. real(real const &x);
  26. real const &operator =(real const &x);
  27. ~real();
  28. real(float f);
  29. real(double f);
  30. real(int i);
  31. real(unsigned int i);
  32. operator float() const;
  33. operator double() const;
  34. operator int() const;
  35. operator unsigned int() const;
  36. real operator +() const;
  37. real operator -() const;
  38. real operator +(real const &x) const;
  39. real operator -(real const &x) const;
  40. real operator *(real const &x) const;
  41. real operator /(real const &x) const;
  42. real const &operator +=(real const &x);
  43. real const &operator -=(real const &x);
  44. real const &operator *=(real const &x);
  45. real const &operator /=(real const &x);
  46. real operator <<(int x) const;
  47. real operator >>(int x) const;
  48. real const &operator <<=(int x);
  49. real const &operator >>=(int x);
  50. bool operator ==(real const &x) const;
  51. bool operator !=(real const &x) const;
  52. bool operator <(real const &x) const;
  53. bool operator >(real const &x) const;
  54. bool operator <=(real const &x) const;
  55. bool operator >=(real const &x) const;
  56. bool operator !() const;
  57. operator bool() const;
  58. /* Trigonometric functions */
  59. friend real sin(real const &x);
  60. friend real cos(real const &x);
  61. friend real tan(real const &x);
  62. friend real asin(real const &x);
  63. friend real acos(real const &x);
  64. friend real atan(real const &x);
  65. friend real atan2(real const &y, real const &x);
  66. /* Hyperbolic functions */
  67. friend real sinh(real const &x);
  68. friend real cosh(real const &x);
  69. friend real tanh(real const &x);
  70. /* Exponential and logarithmic functions */
  71. friend real exp(real const &x);
  72. friend real exp2(real const &x);
  73. friend real log(real const &x);
  74. friend real log2(real const &x);
  75. friend real log10(real const &x);
  76. friend real frexp(real const &x, int *exp);
  77. friend real ldexp(real const &x, int exp);
  78. friend real modf(real const &x, real *iptr);
  79. /* Power functions */
  80. friend real re(real const &x);
  81. friend real sqrt(real const &x);
  82. friend real cbrt(real const &x);
  83. friend real pow(real const &x, real const &y);
  84. friend real gamma(real const &x);
  85. /* Rounding, absolute value, remainder etc. */
  86. friend real ceil(real const &x);
  87. friend real copysign(real const &x, real const &y);
  88. friend real floor(real const &x);
  89. friend real fabs(real const &x);
  90. friend real round(real const &x);
  91. friend real fmod(real const &x, real const &y);
  92. void hexprint() const;
  93. void print(int ndigits = 150) const;
  94. static real const R_0;
  95. static real const R_1;
  96. static real const R_2;
  97. static real const R_3;
  98. static real const R_10;
  99. static real const R_E;
  100. static real const R_LOG2E;
  101. static real const R_LOG10E;
  102. static real const R_LN2;
  103. static real const R_LN10;
  104. static real const R_PI;
  105. static real const R_PI_2;
  106. static real const R_PI_3;
  107. static real const R_PI_4;
  108. static real const R_1_PI;
  109. static real const R_2_PI;
  110. static real const R_2_SQRTPI;
  111. static real const R_SQRT2;
  112. static real const R_SQRT3;
  113. static real const R_SQRT1_2;
  114. /* XXX: changing this requires tuning real::fres (the number of
  115. * Newton-Raphson iterations) and real::print (the number of printed
  116. * digits) */
  117. static int const BIGITS = 16;
  118. static int const BIGIT_BITS = 32;
  119. private:
  120. uint32_t *m_mantissa;
  121. uint32_t m_signexp;
  122. };
  123. } /* namespace lol */
  124. #endif // __LOL_REAL_H__