2
0

Math.hx 3.0 KB

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