Math.hx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package lua;
  23. import haxe.extern.Rest;
  24. /**
  25. Mathematical Functions
  26. **/
  27. @:native("_G.math")
  28. extern class Math {
  29. /**
  30. The value of pi.
  31. **/
  32. static var pi(default, never):Float;
  33. /**
  34. The value HUGE_VAL, a value larger than or equal to any other numerical value.
  35. **/
  36. static var huge(default, never):Float;
  37. /**
  38. Returns the absolute value of x.
  39. **/
  40. static function abs(x:Float):Float;
  41. /**
  42. Returns the smallest integer larger than or equal to x.
  43. **/
  44. static function ceil(x:Float):Int;
  45. /**
  46. Returns the largest integer smaller than or equal to x.
  47. **/
  48. static function floor(x:Float):Int;
  49. /**
  50. Returns the arc cosine of x (in radians).
  51. **/
  52. static function acos(x:Float):Float;
  53. /**
  54. Returns the arc sine of x (in radians).
  55. **/
  56. static function asin(x:Float):Float;
  57. /**
  58. Returns the arc tangent of x (in radians).
  59. **/
  60. static function atan(x:Float):Float;
  61. /**
  62. Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result.
  63. (It also handles correctly the case of x being zero.)
  64. **/
  65. static function atan2(y:Float, x:Float):Float;
  66. /**
  67. Returns the cosine of x (assumed to be in radians).
  68. **/
  69. static function cos(x:Float):Float;
  70. /**
  71. Returns the hyperbolic cosine of x.
  72. **/
  73. static function cosh(x:Float):Float;
  74. /**
  75. Returns the sine of x (assumed to be in radians).
  76. **/
  77. static function sin(x:Float):Float;
  78. /**
  79. Returns the hyperbolic sine of x.
  80. **/
  81. static function sinh(x:Float):Float;
  82. /**
  83. Returns the tangent of x (assumed to be in radians)
  84. **/
  85. static function tan(x:Float):Float;
  86. /**
  87. Returns the hyperbolic tangent of x.
  88. **/
  89. static function tanh(x:Float):Float;
  90. /**
  91. Returns the angle x (given in degrees) in radians.
  92. **/
  93. static function rad(x:Float):Float;
  94. /**
  95. Returns two numbers, the integral part of x and the fractional part of x.
  96. **/
  97. static function modf(x:Float):Float;
  98. /**
  99. Returns the remainder of the division of x by y that rounds the quotient towards zero.
  100. **/
  101. static function fmod(x:Float):Float;
  102. /**
  103. Returns y-th power of x.
  104. **/
  105. static function pow(x:Float, y:Float):Float;
  106. /**
  107. Returns the square root of x.
  108. **/
  109. static function sqrt(x:Float):Float;
  110. /**
  111. Returns the value e^x.
  112. **/
  113. static function exp(x:Float):Float;
  114. /**
  115. Returns m and e such that x = m2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).
  116. **/
  117. static function frexp(x:Float):MathFrexpResult;
  118. /**
  119. Returns m2^e (e should be an integer).
  120. **/
  121. static function ldexp(m:Float, e:Int):Float;
  122. /**
  123. Returns the natural logarithm of x.
  124. **/
  125. static function log(x:Float):Float;
  126. /**
  127. Returns the base-10 logarithm of x.
  128. **/
  129. static function log10(x:Float):Float;
  130. /**
  131. Returns the maximum value among its arguments.
  132. **/
  133. static function max(x:Float, numbers:Rest<Float>):Float;
  134. /**
  135. Returns the minimum value among its arguments.
  136. **/
  137. static function min(x:Float, numbers:Rest<Float>):Float;
  138. /**
  139. Returns the angle x (given in radians) in degrees.
  140. **/
  141. static function deg(x:Float):Float;
  142. /**
  143. This function is an interface to the simple pseudo-random generator function rand provided by ANSI C.
  144. (No guarantees can be given for its statistical properties.)
  145. When called without arguments, returns a uniform pseudo-random real number in the range [0,1).
  146. When called with an integer number `m`, returns a uniform pseudo-random integer in the range [1, m].
  147. When called with two integer numbers `m` and `n`, returns a uniform pseudo-random integer in the range [m, n].
  148. **/
  149. static function random(?m:Float, ?n:Float):Float;
  150. /**
  151. Sets `x` as the "seed" for the pseudo-random generator: equal seeds produce equal sequences of numbers.
  152. **/
  153. static function randomseed(x:Float):Float;
  154. }
  155. /**
  156. The return value of `Math.frexp`.
  157. **/
  158. @:multiReturn extern class MathFrexpResult {
  159. var m:Float;
  160. var e:Int;
  161. }