Math.hx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C)2005-2017 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;
  23. // Can't enable @:coreApi because some fields are now inline getters
  24. // @:coreApi
  25. @:keepInit
  26. extern class Math
  27. {
  28. static var PI(default,null) : Float;
  29. static var NEGATIVE_INFINITY(get, null) : Float;
  30. @:pure private static inline function get_NEGATIVE_INFINITY () : Float {
  31. return -(untyped __js__("Infinity"));
  32. }
  33. static var POSITIVE_INFINITY(get,null) : Float;
  34. @:pure private static inline function get_POSITIVE_INFINITY () : Float {
  35. return (untyped __js__("Infinity"));
  36. }
  37. static var NaN(get, null) : Float;
  38. @:pure private static inline function get_NaN () : Float {
  39. return (untyped __js__("NaN"));
  40. }
  41. @:pure static function abs(v:Float):Float;
  42. @:pure static function acos(v:Float):Float;
  43. @:pure static function asin(v:Float):Float;
  44. @:pure static function atan(v:Float):Float;
  45. @:pure static function atan2(y:Float, x:Float):Float;
  46. @:pure static function ceil(v:Float):Int;
  47. @:pure static function cos(v:Float):Float;
  48. @:pure static function exp(v:Float):Float;
  49. @:pure static function floor(v:Float):Int;
  50. @:pure static function log(v:Float):Float;
  51. @:pure static function max(a:Float, b:Float):Float;
  52. @:pure static function min(a:Float, b:Float):Float;
  53. @:pure static function pow(v:Float, exp:Float):Float;
  54. static function random() : Float;
  55. @:pure static function round(v:Float):Int;
  56. @:pure static function sin(v:Float):Float;
  57. @:pure static function sqrt(v:Float):Float;
  58. @:pure static function tan(v:Float):Float;
  59. @:pure static inline function ffloor( v : Float ) : Float {
  60. return floor(v);
  61. }
  62. @:pure static inline function fceil( v : Float ) : Float {
  63. return ceil(v);
  64. }
  65. @:pure static inline function fround( v : Float ) : Float {
  66. return round(v);
  67. }
  68. @:pure static inline function isFinite( f : Float ) : Bool {
  69. return (untyped __js__("isFinite"))(f);
  70. }
  71. @:pure static inline function isNaN( f : Float ) : Bool {
  72. return (untyped __js__("isNaN"))(f);
  73. }
  74. static function __init__() : Void {
  75. untyped __feature__("Type.resolveClass", $hxClasses["Math"] = Math);
  76. }
  77. }