Math.hx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 js.lib;
  23. import haxe.extern.Rest;
  24. /**
  25. Math is a built-in object that has properties and methods for mathematical constants and functions.
  26. Not a function object.
  27. Documentation [Math](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  28. **/
  29. @:native("Math")
  30. extern class Math {
  31. /**
  32. Euler's constant and the base of natural logarithms, approximately 2.718.
  33. **/
  34. static var E(default,never):Float;
  35. /**
  36. Natural logarithm of 2, approximately 0.693.
  37. **/
  38. static var LN2(default,never):Float;
  39. /**
  40. Natural logarithm of 10, approximately 2.303.
  41. **/
  42. static var LN10(default,never):Float;
  43. /**
  44. Base 2 logarithm of E, approximately 1.443.
  45. **/
  46. static var LOG2E(default,never):Float;
  47. /**
  48. Base 10 logarithm of E, approximately 0.434.
  49. **/
  50. static var LOG10E(default,never):Float;
  51. /**
  52. Ratio of the circumference of a circle to its diameter, approximately 3.14159.
  53. **/
  54. static var PI(default,never):Float;
  55. /**
  56. Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
  57. **/
  58. static var SQRT1_2(default,never):Float;
  59. /**
  60. Square root of 2, approximately 1.414.
  61. **/
  62. static var SQRT2(default,never):Float;
  63. /**
  64. Returns the absolute value of a number.
  65. **/
  66. @:overload(function(x:Float):Float {})
  67. @:pure static function abs(x:Int):Int;
  68. /**
  69. Returns the arccosine of a number.
  70. **/
  71. @:pure static function acos(x:Float):Float;
  72. /**
  73. Returns the hyperbolic arccosine of a number.
  74. **/
  75. @:pure static function acosh(x:Float):Float;
  76. /**
  77. Returns the arcsine of a number.
  78. **/
  79. @:pure static function asin(x:Float):Float;
  80. /**
  81. Returns the hyperbolic arcsine of a number.
  82. **/
  83. @:pure static function asinh(x:Float):Float;
  84. /**
  85. Returns the arctangent of a number.
  86. **/
  87. @:pure static function atan(x:Float):Float;
  88. /**
  89. Returns the hyperbolic arctangent of a number.
  90. **/
  91. @:pure static function atanh(x:Float):Float;
  92. /**
  93. Returns the arctangent of the quotient of its arguments.
  94. **/
  95. @:pure static function atan2(y:Float, x:Float):Float;
  96. /**
  97. Returns the cube root of a number.
  98. **/
  99. @:pure static function cbrt(x:Float):Float;
  100. /**
  101. Returns the smallest integer greater than or equal to a number.
  102. **/
  103. @:pure static function ceil(x:Float):Int;
  104. /**
  105. Returns the number of leading zeroes of a 32-bit integer.
  106. **/
  107. @:pure static function clz32(x:Int):Int;
  108. /**
  109. Returns the cosine of a number.
  110. **/
  111. @:pure static function cos(x:Float):Float;
  112. /**
  113. Returns the hyperbolic cosine of a number.
  114. **/
  115. @:pure static function cosh(x:Float):Float;
  116. /**
  117. Returns Ex, where x is the argument, and E is Euler's constant (2.718…), the base of the natural logarithm.
  118. **/
  119. @:pure static function exp(x:Float):Float;
  120. /**
  121. Returns subtracting 1 from exp(x).
  122. **/
  123. @:pure static function expm1(x:Float):Float;
  124. /**
  125. Returns the largest integer less than or equal to a number.
  126. **/
  127. @:pure static function floor(x:Float):Int;
  128. /**
  129. Returns the nearest single precision float representation of a number.
  130. **/
  131. @:pure static function fround(x:Float):Float;
  132. /**
  133. Returns the square root of the sum of squares of its arguments.
  134. **/
  135. @:pure static function hypot(args:Rest<Float>):Float;
  136. /**
  137. Returns the result of a 32-bit integer multiplication.
  138. **/
  139. @:pure static function imul(x:Int, y:Int):Int;
  140. /**
  141. Returns the natural logarithm (loge, also ln) of a number.
  142. **/
  143. @:pure static function log(x:Float):Float;
  144. /**
  145. Returns the natural logarithm (loge, also ln) of 1 + x for a number x.
  146. **/
  147. @:pure static function log1p(x:Float):Float;
  148. /**
  149. Returns the base 10 logarithm of a number.
  150. **/
  151. @:pure static function log10(x:Float):Float;
  152. /**
  153. Returns the base 2 logarithm of a number.
  154. **/
  155. @:pure static function log2(x:Float):Float;
  156. /**
  157. Returns the largest of zero or more numbers.
  158. **/
  159. @:overload(function(args:Rest<Float>):Float {})
  160. @:pure static function max(args:Rest<Int>):Int;
  161. /**
  162. Returns the smallest of zero or more numbers.
  163. **/
  164. @:overload(function(args:Rest<Float>):Float {})
  165. @:pure static function min(args:Rest<Int>):Int;
  166. /**
  167. Returns base to the exponent power, that is, baseexponent.
  168. **/
  169. @:pure static function pow(x:Float, y:Float):Float;
  170. /**
  171. Returns a pseudo-random number between 0 and 1.
  172. **/
  173. @:pure static function random():Float;
  174. /**
  175. Returns the value of a number rounded to the nearest integer.
  176. **/
  177. @:pure static function round(x:Float):Int;
  178. /**
  179. Returns the sign of the x, indicating whether x is positive, negative or zero.
  180. **/
  181. @:pure static function sign(x:Float):Int;
  182. /**
  183. Returns the sine of a number.
  184. **/
  185. @:pure static function sin(x:Float):Float;
  186. /**
  187. Returns the hyperbolic sine of a number.
  188. **/
  189. @:pure static function sinh(x:Float):Float;
  190. /**
  191. Returns the positive square root of a number.
  192. **/
  193. @:pure static function sqrt(x:Float):Float;
  194. /**
  195. Returns the tangent of a number.
  196. **/
  197. @:pure static function tan(x:Float):Float;
  198. /**
  199. Returns the hyperbolic tangent of a number.
  200. **/
  201. @:pure static function tanh(x:Float):Float;
  202. /**
  203. Returns the integer part of the number x, removing any fractional digits.
  204. **/
  205. @:pure static function trunc(x:Float):Int;
  206. }