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 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. void setUp() {}
  22. void tearDown() {}
  23. LOLUNIT_TEST(test_sin)
  24. {
  25. for (int i = -10000; i < 10000; i++)
  26. {
  27. double f = (double)i * (1.0 / 1000.0);
  28. #if defined __GNUC__
  29. double a = __builtin_sin(f);
  30. #else
  31. double a = sin(f);
  32. #endif
  33. double b = lol_sin(f);
  34. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  35. }
  36. for (int i = -10000; i < 10000; i++)
  37. {
  38. double f = (double)i * (1.0 / 100000.0);
  39. #if defined __GNUC__
  40. double a = __builtin_sin(f);
  41. #else
  42. double a = sin(f);
  43. #endif
  44. double b = lol_sin(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_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  60. }
  61. for (int i = -10000; i < 10000; i++)
  62. {
  63. double f = (double)i * (1.0 / 100000.0);
  64. #if defined __GNUC__
  65. double a = __builtin_cos(f);
  66. #else
  67. double a = cos(f);
  68. #endif
  69. double b = lol_cos(f);
  70. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  71. }
  72. }
  73. LOLUNIT_TEST(test_sincos)
  74. {
  75. for (int i = -10000; i < 10000; i++)
  76. {
  77. double f = (double)i * (1.0 / 1000.0);
  78. #if defined __GNUC__
  79. double a1 = __builtin_sin(f);
  80. double a2 = __builtin_cos(f);
  81. #else
  82. double a1 = sin(f);
  83. double a2 = cos(f);
  84. #endif
  85. double b1, b2;
  86. lol_sincos(f, &b1, &b2);
  87. LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11);
  88. LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11);
  89. }
  90. for (int i = -10000; i < 10000; i++)
  91. {
  92. double f = (double)i * (1.0 / 100000.0);
  93. #if defined __GNUC__
  94. double a1 = __builtin_sin(f);
  95. double a2 = __builtin_cos(f);
  96. #else
  97. double a1 = sin(f);
  98. double a2 = cos(f);
  99. #endif
  100. double b1, b2;
  101. lol_sincos(f, &b1, &b2);
  102. LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11);
  103. LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11);
  104. }
  105. }
  106. LOLUNIT_TEST(test_tan)
  107. {
  108. for (int i = -100000; i < 100000; i++)
  109. {
  110. double f = (double)i * (1.0 / 10000.0);
  111. #if defined __GNUC__
  112. double a = __builtin_tan(f);
  113. #else
  114. double a = tan(f);
  115. #endif
  116. double b = lol_tan(f);
  117. if (fabs(a) > 1e4)
  118. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11);
  119. else if (fabs(a) > 1.0)
  120. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11);
  121. else
  122. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  123. }
  124. for (int i = -10000; i < 10000; i++)
  125. {
  126. double f = (double)i * (1.0 / 100000.0);
  127. #if defined __GNUC__
  128. double a = __builtin_tan(f);
  129. #else
  130. double a = tan(f);
  131. #endif
  132. double b = lol_tan(f);
  133. if (fabs(a) > 1e4)
  134. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11);
  135. else if (fabs(a) > 1.0)
  136. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11);
  137. else
  138. LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11);
  139. }
  140. }
  141. };
  142. } /* namespace lol */