Math.hx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C)2005-2012 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. @:native("_G.math")
  27. extern class Math
  28. {
  29. static var PI(get,null) : Float;
  30. private static inline function get_PI () : Float {
  31. return untyped Math.pi;
  32. }
  33. static var NEGATIVE_INFINITY(get, null) : Float;
  34. private static inline function get_NEGATIVE_INFINITY () : Float {
  35. return untyped Math.huge;
  36. }
  37. static var POSITIVE_INFINITY(get,null) : Float;
  38. private static inline function get_POSITIVE_INFINITY () : Float {
  39. return untyped -Math.huge;
  40. }
  41. static var NaN(get, null) : Float;
  42. private static inline function get_NaN () : Float {
  43. return 0/0;
  44. }
  45. static function abs(v:Float):Float;
  46. static function acos(v:Float):Float;
  47. static function asin(v:Float):Float;
  48. static function atan(v:Float):Float;
  49. static function atan2(y:Float, x:Float):Float;
  50. static function ceil(v:Float):Int;
  51. static function cos(v:Float):Float;
  52. static function exp(v:Float):Float;
  53. static function floor(v:Float):Int;
  54. static function log(v:Float):Float;
  55. static function max(a:Float, b:Float):Float;
  56. static function min(a:Float, b:Float):Float;
  57. static function pow(v:Float, exp:Float):Float;
  58. static function random() : Float;
  59. static inline function round(v:Float):Int {
  60. return Std.int(v + 0.5);
  61. }
  62. static function sin(v:Float):Float;
  63. static function sqrt(v:Float):Float;
  64. static function tan(v:Float):Float;
  65. static inline function ffloor( v : Float ) : Float {
  66. return floor(v);
  67. }
  68. static inline function fceil( v : Float ) : Float {
  69. return ceil(v);
  70. }
  71. static inline function fround( v : Float ) : Float {
  72. return round(v);
  73. }
  74. static inline function isFinite( f : Float ) : Bool {
  75. return (f > Math.NEGATIVE_INFINITY && f < Math.POSITIVE_INFINITY);
  76. }
  77. static inline function isNaN( f : Float ) : Bool {
  78. return (f != f);
  79. }
  80. static function __init__() : Void {
  81. untyped __feature__("Type.resolveClass", $hxClasses["Math"] = Math);
  82. }
  83. }