Math.hx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. @:core_api class Math
  26. {
  27. public static var PI(default,null) : Float;
  28. public static var NaN(default,null) : Float;
  29. public static var POSITIVE_INFINITY(default,null) : Float;
  30. public static var NEGATIVE_INFINITY(default,null) : Float;
  31. public static function abs(v : Float) : Float { return untyped __call__("abs", v); }
  32. public static function min(a : Float,b : Float) : Float { return untyped __call__("min", a, b); }
  33. public static function max(a : Float,b : Float) : Float { return untyped __call__("max", a, b); }
  34. public static function sin(v : Float) : Float { return untyped __call__("sin", v); }
  35. public static function cos(v : Float) : Float { return untyped __call__("cos", v); }
  36. public static function atan2(y : Float,x : Float) : Float { return untyped __call__("atan2", y, x); }
  37. public static function tan(v : Float) : Float { return untyped __call__("tan", v); }
  38. public static function exp(v : Float) : Float { return untyped __call__("exp", v); }
  39. public static function log(v : Float) : Float { return untyped __call__("log", v); }
  40. public static function sqrt(v : Float) : Float { return untyped __call__("sqrt", v); }
  41. public static function round(v : Float) : Int { return untyped __call__("(int) floor", v + 0.5); }
  42. public static function floor(v : Float) : Int { return untyped __call__("(int) floor", v); }
  43. public static function ceil(v : Float) : Int { return untyped __call__("(int) ceil", v); }
  44. public static function atan(v : Float) : Float { return untyped __call__("atan", v); }
  45. public static function asin(v : Float) : Float { return untyped __call__("asin", v); }
  46. public static function acos(v : Float) : Float { return untyped __call__("acos", v); }
  47. public static function pow(v : Float,exp : Float) : Float { return untyped __call__("pow", v, exp); }
  48. public static function random() : Float { return untyped __call__("mt_rand") / __call__("mt_getrandmax"); }
  49. public static function isNaN(f : Float) : Bool { return untyped __call__("is_nan", f); }
  50. public static function isFinite(f : Float) : Bool { return untyped __call__("is_finite", f); }
  51. static function __init__() : Void {
  52. PI = untyped __php__("M_PI");
  53. NaN = untyped __php__("acos(1.01)");
  54. NEGATIVE_INFINITY = untyped __php__("log(0)");
  55. POSITIVE_INFINITY = -NEGATIVE_INFINITY;
  56. }
  57. }