Browse Source

moved some stuff from Std to Math.

Nicolas Cannasse 19 years ago
parent
commit
79beaa0e7e
6 changed files with 59 additions and 49 deletions
  1. 35 0
      std/Math.hx
  2. 0 40
      std/Std.hx
  3. 2 2
      std/haxe/Serializer.hx
  4. 4 4
      std/haxe/Unserializer.hx
  5. 0 1
      std/neko/Boot.hx
  6. 18 2
      std/neko/NekoMath__.hx

+ 35 - 0
std/Math.hx

@@ -26,6 +26,9 @@
 extern class Math
 {
 	static var PI : Float;
+	static var NaN : Float;
+	static var NEGATIVE_INFINITY : Float;
+	static var POSITIVE_INFINITY : Float;
 
 	static function abs(value:Float):Float;
 	static function min(value1:Float,value2:Float):Float;
@@ -45,6 +48,38 @@ extern class Math
 	static function acos(value:Float):Float;
 	static function pow(value1:Float,value2:Float):Float;
 	static function random() : Float;
+
+	static function isFinite( f : Float ) : Bool;
+	static function isNaN( f : Float ) : Bool;
+
+	private static function __init__() : Void untyped {
+	#if neko
+		Math = neko.NekoMath__;
+	#else true
+		NaN = Number.NaN;
+		NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;
+		POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
+		isFinite = function(i) {
+			return
+			#if flash
+			_global.isFinite(i);
+			#else js
+			__js__("isFinite")(i);
+			#else error
+			#end
+		};
+		isNaN = function(i) {
+			return
+			#if flash
+			_global.isNaN(i);
+			#else js
+			__js__("isNaN")(i);
+			#else error
+			#end
+		};
+	#end
+	}
+
 }
 
 

+ 0 - 40
std/Std.hx

@@ -28,16 +28,6 @@
 **/
 class Std {
 
-	/**
-		The infinity Float value.
-	**/
-	public static var infinity = 1.0 / 0.0;
-
-	/**
-		The not-a-number Float value.
-	**/
-	public static var nan = 0.0 / 0.0;
-
 	/**
 		Tells if a value v is of the type t.
 	**/
@@ -157,36 +147,6 @@ class Std {
 		#end
 	}
 
-	/**
-		Tells if a Float value is finite.
-	**/
-	public static function isFinite(i : Float) : Bool {
-		return untyped
-		#if flash
-		_global.isFinite(i);
-		#else neko
-		!__dollar__isinfinite(i);
-		#else js
-		__js__("isFinite")(i);
-		#else error
-		#end
-	}
-
-	/**
-		Tells if a Float value is not-a-number.
-	**/
-	public static function isNaN(i : Float) : Bool {
-		return untyped
-		#if flash
-		_global.isNaN(i);
-		#else neko
-		__dollar__isnan(i);
-		#else js
-		__js__("isNaN")(i);
-		#else error
-		#end
-	}
-
 	/**
 		Return a random integer between 0 included and x excluded.
 	**/

+ 2 - 2
std/haxe/Serializer.hx

@@ -118,9 +118,9 @@ class Serializer {
 			return;
 		}
 		if( Std.is(v,Float) ) {
-			if( Std.isNaN(v) )
+			if( Math.isNaN(v) )
 				buf.add("k");
-			else if( !Std.isFinite(v) )
+			else if( !Math.isFinite(v) )
 				buf.add(if( v < 0 ) "m" else "p");
 			else {
 				buf.add("d");

+ 4 - 4
std/haxe/Unserializer.hx

@@ -47,7 +47,7 @@ class Unserializer {
  			if( c == null )
  				break;
  			#else true
-			if( Std.isNaN(c) )
+			if( Math.isNaN(c) )
 				break;
 			#end
  			if( c == 45 ) { // negative sign
@@ -112,11 +112,11 @@ class Unserializer {
  				throw ("Invalid float "+s);
  			return f;
  		case 107: // k
- 			return Std.nan;
+ 			return Math.NaN;
  		case 109: // m
- 			return -Std.infinity;
+ 			return Math.NEGATIVE_INFINITY;
  		case 112: // p
- 			return Std.infinity;
+ 			return Math.POSITIVE_INFINITY;
  		case 115: // s
  			var len = readDigits();
  			if( buf.charAt(pos++) == ":" ) {

+ 0 - 1
std/neko/Boot.hx

@@ -128,7 +128,6 @@ class Boot {
 		untyped {
 			String = NekoString__;
 			Array = NekoArray__;
-			Math = NekoMath__;
 			Int = __dollar__new(null);
 			Float = __dollar__new(null);
 			Bool = __dollar__new(null);

+ 18 - 2
std/neko/NekoMath__.hx

@@ -26,7 +26,11 @@ package neko;
 
 class NekoMath__
 {
-	static var PI = Lib.load("std","math_pi",0)();
+	static var PI;
+	static var NaN;
+	static var POSITIVE_INFINITY;
+	static var NEGATIVE_INFINITY;
+
 	static var abs = Lib.load("std","math_abs",1);
 	static function min(a,b) { return if( a < b ) a else b; }
 	static function max(a,b) { return if( a < b ) b else a; }
@@ -45,10 +49,22 @@ class NekoMath__
 	static var acos = Lib.load("std","math_acos",1);
 	static var pow = Lib.load("std","math_pow",2);
 
-	static var __rnd = Lib.load("std","random_new",0)();
+	static var __rnd;
 	static var _rand_float = Lib.load("std","random_float",1);
 	static var _rand_int = Lib.load("std","random_int",2);
 	static function random() { return _rand_float(__rnd); }
+
+	static function isNaN(f) { return untyped __dollar__isnan(f); }
+	static function isFinite(f) { return !untyped __dollar__isinfinite(f); }
+
+	static function __init__() {
+	 	__rnd = Lib.load("std","random_new",0)();
+	 	PI = Lib.load("std","math_pi",0)();
+	 	NaN = 0.0 / 0.0;
+	 	POSITIVE_INFINITY = 1.0 / 0.0;
+	 	NEGATIVE_INFINITY = -POSITIVE_INFINITY;
+	}
+
 }