You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cmath>
  14. #include "core.h"
  15. #include "lol/unit.h"
  16. namespace lol
  17. {
  18. LOLUNIT_FIXTURE(TrigTest)
  19. {
  20. public:
  21. LOLUNIT_TEST(test_sin)
  22. {
  23. for (int i = -10000; i < 10000; i++)
  24. {
  25. double f = (double)i * (1.0 / 1000.0);
  26. #if defined __GNUC__
  27. double a = __builtin_sin(f);
  28. #else
  29. double a = sin(f);
  30. #endif
  31. double b = lol_sin(f);
  32. LOLUNIT_SET_CONTEXT(f);
  33. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  34. }
  35. for (int i = -10000; i < 10000; i++)
  36. {
  37. double f = (double)i * (1.0 / 100000.0);
  38. #if defined __GNUC__
  39. double a = __builtin_sin(f);
  40. #else
  41. double a = sin(f);
  42. #endif
  43. double b = lol_sin(f);
  44. LOLUNIT_SET_CONTEXT(f);
  45. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  46. }
  47. }
  48. LOLUNIT_TEST(test_cos)
  49. {
  50. for (int i = -10000; i < 10000; i++)
  51. {
  52. double f = (double)i * (1.0 / 1000.0);
  53. #if defined __GNUC__
  54. double a = __builtin_cos(f);
  55. #else
  56. double a = cos(f);
  57. #endif
  58. double b = lol_cos(f);
  59. LOLUNIT_SET_CONTEXT(f);
  60. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  61. }
  62. for (int i = -10000; i < 10000; i++)
  63. {
  64. double f = (double)i * (1.0 / 100000.0);
  65. #if defined __GNUC__
  66. double a = __builtin_cos(f);
  67. #else
  68. double a = cos(f);
  69. #endif
  70. double b = lol_cos(f);
  71. LOLUNIT_SET_CONTEXT(f);
  72. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  73. }
  74. }
  75. LOLUNIT_TEST(test_sincos)
  76. {
  77. for (int i = -10000; i < 10000; i++)
  78. {
  79. double f = (double)i * (1.0 / 1000.0);
  80. #if defined __GNUC__
  81. double a1 = __builtin_sin(f);
  82. double a2 = __builtin_cos(f);
  83. #else
  84. double a1 = sin(f);
  85. double a2 = cos(f);
  86. #endif
  87. double b1, b2;
  88. lol_sincos(f, &b1, &b2);
  89. LOLUNIT_SET_CONTEXT(f);
  90. LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11);
  91. LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11);
  92. }
  93. for (int i = -10000; i < 10000; i++)
  94. {
  95. double f = (double)i * (1.0 / 100000.0);
  96. #if defined __GNUC__
  97. double a1 = __builtin_sin(f);
  98. double a2 = __builtin_cos(f);
  99. #else
  100. double a1 = sin(f);
  101. double a2 = cos(f);
  102. #endif
  103. double b1, b2;
  104. lol_sincos(f, &b1, &b2);
  105. LOLUNIT_SET_CONTEXT(f);
  106. LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11);
  107. LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11);
  108. }
  109. }
  110. LOLUNIT_TEST(test_tan)
  111. {
  112. for (int i = -100000; i < 100000; i++)
  113. {
  114. double f = (double)i * (1.0 / 10000.0);
  115. #if defined __GNUC__
  116. double a = __builtin_tan(f);
  117. #else
  118. double a = tan(f);
  119. #endif
  120. double b = lol_tan(f);
  121. LOLUNIT_SET_CONTEXT(f);
  122. if (fabs(a) > 1e4)
  123. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11);
  124. else if (fabs(a) > 1.0)
  125. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11);
  126. else
  127. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  128. }
  129. for (int i = -10000; i < 10000; i++)
  130. {
  131. double f = (double)i * (1.0 / 100000.0);
  132. #if defined __GNUC__
  133. double a = __builtin_tan(f);
  134. #else
  135. double a = tan(f);
  136. #endif
  137. double b = lol_tan(f);
  138. LOLUNIT_SET_CONTEXT(f);
  139. if (fabs(a) > 1e4)
  140. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11);
  141. else if (fabs(a) > 1.0)
  142. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11);
  143. else
  144. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  145. }
  146. }
  147. };
  148. } /* namespace lol */