No Description
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.

080-TestSystemMath.cs 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using System;
  2. using Burst.Compiler.IL.Tests.Helpers;
  3. namespace Burst.Compiler.IL.Tests
  4. {
  5. /// <summary>
  6. /// Tests of the <see cref="System.Math"/> functions.
  7. /// </summary>
  8. internal class TestSystemMath
  9. {
  10. [TestCompiler(DataRange.Standard)]
  11. public static double TestCos(float value)
  12. {
  13. return Math.Cos(value);
  14. }
  15. [TestCompiler(DataRange.Standard)]
  16. public static double TestSin(float value)
  17. {
  18. return Math.Sin(value);
  19. }
  20. [TestCompiler(DataRange.Standard)]
  21. public static float TestTan(float value)
  22. {
  23. return (float) Math.Tan(value);
  24. }
  25. [TestCompiler(DataRange.Standard11)]
  26. public static double TestAcos(float value)
  27. {
  28. return Math.Acos(value);
  29. }
  30. [TestCompiler(DataRange.Standard11)]
  31. public static double TestAsin(float value)
  32. {
  33. return Math.Asin(value);
  34. }
  35. [TestCompiler(DataRange.Standard11)]
  36. public static float TestAtan(float value)
  37. {
  38. return (float)Math.Atan(value);
  39. }
  40. [TestCompiler(DataRange.ZeroExclusiveToOneInclusive, DataRange.ZeroExclusiveToOneInclusive)]
  41. public static float TestAtan2(float y, float x)
  42. {
  43. return (float)Math.Atan2(y, x);
  44. }
  45. [TestCompiler(DataRange.Standard)]
  46. public static double TestCosh(float value)
  47. {
  48. return Math.Cosh(value);
  49. }
  50. [TestCompiler(DataRange.Standard)]
  51. public static double TestSinh(float value)
  52. {
  53. return Math.Sinh(value);
  54. }
  55. [TestCompiler(DataRange.Standard)]
  56. public static float TestTanh(float value)
  57. {
  58. return (float)Math.Tanh(value);
  59. }
  60. [TestCompiler(DataRange.StandardPositive)]
  61. public static double TestSqrt(float value)
  62. {
  63. return Math.Sqrt(value);
  64. }
  65. [TestCompiler(DataRange.StandardPositive & ~DataRange.Zero)]
  66. public static double TestLog(float value)
  67. {
  68. return Math.Log(value);
  69. }
  70. [TestCompiler(DataRange.StandardPositive & ~DataRange.Zero)]
  71. public static double TestLog10(float value)
  72. {
  73. return Math.Log10(value);
  74. }
  75. [TestCompiler(DataRange.StandardPositive)]
  76. public static double TestExp(float value)
  77. {
  78. return Math.Exp(value);
  79. }
  80. [TestCompiler(DataRange.Standard & ~(DataRange.Zero|DataRange.NaN), DataRange.Standard)]
  81. [TestCompiler(DataRange.Standard & ~DataRange.Zero, DataRange.Standard & ~DataRange.Zero)]
  82. public static double TestPow(float value, float power)
  83. {
  84. return Math.Pow(value, power);
  85. }
  86. [TestCompiler(DataRange.Standard)]
  87. public static sbyte TestAbsSByte(sbyte value)
  88. {
  89. return Math.Abs(value);
  90. }
  91. [TestCompiler(DataRange.Standard)]
  92. public static short TestAbsShort(short value)
  93. {
  94. return Math.Abs(value);
  95. }
  96. [TestCompiler(DataRange.Standard)]
  97. public static int TestAbsInt(int value)
  98. {
  99. return Math.Abs(value);
  100. }
  101. [TestCompiler(DataRange.Standard)]
  102. public static long TestAbsLong(long value)
  103. {
  104. return Math.Abs(value);
  105. }
  106. [TestCompiler(DataRange.Standard)]
  107. public static float TestAbsFloat(float value)
  108. {
  109. return Math.Abs(value);
  110. }
  111. [TestCompiler(DataRange.Standard)]
  112. public static double TestAbsDouble(double value)
  113. {
  114. return Math.Abs(value);
  115. }
  116. [TestCompiler(DataRange.Standard, DataRange.Standard)]
  117. public static int TestMaxInt(int left, int right)
  118. {
  119. return Math.Max(left, right);
  120. }
  121. [TestCompiler(DataRange.Standard, DataRange.Standard)]
  122. public static int TestMinInt(int left, int right)
  123. {
  124. return Math.Min(left, right);
  125. }
  126. [TestCompiler(DataRange.Standard, DataRange.Standard)]
  127. public static double TestMaxDouble(double left, double right)
  128. {
  129. return Math.Max(left, right);
  130. }
  131. [TestCompiler(DataRange.Standard, DataRange.Standard)]
  132. public static double TestMinDouble(double left, double right)
  133. {
  134. return Math.Min(left, right);
  135. }
  136. [TestCompiler(DataRange.Standard)]
  137. public static int TestSignInt(int value)
  138. {
  139. return Math.Sign(value);
  140. }
  141. [TestCompiler(DataRange.Standard & ~DataRange.NaN)]
  142. public static int TestSignFloat(float value)
  143. {
  144. return Math.Sign(value);
  145. }
  146. [TestCompiler(float.NaN, ExpectedException = typeof(ArithmeticException))]
  147. [MonoOnly(".NET CLR does not support burst.abort correctly")]
  148. public static int TestSignException(float value)
  149. {
  150. return Math.Sign(value);
  151. }
  152. [TestCompiler(DataRange.Standard & ~DataRange.NaN)]
  153. public static int TestSignDouble(double value)
  154. {
  155. return Math.Sign(value);
  156. }
  157. [TestCompiler(DataRange.Standard)]
  158. public static double TestCeilingDouble(double value)
  159. {
  160. return Math.Ceiling(value);
  161. }
  162. [TestCompiler(DataRange.Standard)]
  163. public static double TestFloorDouble(double value)
  164. {
  165. return Math.Floor(value);
  166. }
  167. [TestCompiler(DataRange.Standard)]
  168. public static double TestRoundDouble(double value)
  169. {
  170. return Math.Round(value);
  171. }
  172. [TestCompiler(DataRange.Standard)]
  173. public static double TestTruncateDouble(double value)
  174. {
  175. return Math.Truncate(value);
  176. }
  177. [TestCompiler(DataRange.Standard, DataRange.Standard & ~DataRange.Zero)]
  178. public static int TestDivRemInt(int a, int b)
  179. {
  180. int remResult;
  181. var divResult = Math.DivRem(a, b, out remResult);
  182. return divResult + remResult * 7;
  183. }
  184. [TestCompiler(DataRange.Standard, DataRange.Standard)]
  185. [TestCompiler(int.MaxValue, DataRange.Standard)]
  186. public static long TestBigMulInt(int a, int b)
  187. {
  188. return Math.BigMul(a, b);
  189. }
  190. [TestCompiler(DataRange.Standard & ~DataRange.Zero, DataRange.Standard & ~DataRange.Zero)]
  191. public static double TestLogWithBaseDouble(double a, double newBase)
  192. {
  193. return Math.Log(a, newBase);
  194. }
  195. //[TestCompiler(1.0, 2.0)]
  196. //[TestCompiler(10.0, 3.0)]
  197. //[TestCompiler(15.0, 4.0)]
  198. //[Ignore("Not yet supported")]
  199. //public static double TestIEEERemainder(double a, double newBase)
  200. //{
  201. // return Math.IEEERemainder(a, newBase);
  202. //}
  203. [TestCompiler(DataRange.Standard)]
  204. public static bool TestIsNanDouble(double a)
  205. {
  206. return double.IsNaN(a);
  207. }
  208. [TestCompiler(DataRange.Standard)]
  209. public static bool TestIsNanFloat(float a)
  210. {
  211. return float.IsNaN(a);
  212. }
  213. [TestCompiler(DataRange.Standard)]
  214. public static bool TestIsInfinityDouble(double a)
  215. {
  216. return double.IsInfinity(a);
  217. }
  218. [TestCompiler(DataRange.Standard)]
  219. public static bool TestIsInfinityFloat(float a)
  220. {
  221. return float.IsInfinity(a);
  222. }
  223. }
  224. }