Browse Source

fixed Std.random(-100) and add to changes (potential backward incompatibility)

Nicolas Cannasse 13 years ago
parent
commit
8c38fc32f2
4 changed files with 5 additions and 4 deletions
  1. 2 1
      doc/CHANGES.txt
  2. 1 1
      std/flash/_std/Std.hx
  3. 1 1
      std/js/_std/Std.hx
  4. 1 1
      std/php/_std/Std.hx

+ 2 - 1
doc/CHANGES.txt

@@ -6,7 +6,8 @@
 	all : allow any type constraint for type parameters
 	all : allow any type constraint for type parameters
 	all : make property type optional (when a initial value is set)
 	all : make property type optional (when a initial value is set)
 	all : new post-compilation DCE
 	all : new post-compilation DCE
-	
+	all : Std.random(x) when x <= 0 is now always 0
+
 2012-07-16: 2.10
 2012-07-16: 2.10
 	java/cs : added two new targets (beta)
 	java/cs : added two new targets (beta)
 	all : fixed List and Null<T> for first, last, pop
 	all : fixed List and Null<T> for first, last, pop

+ 1 - 1
std/flash/_std/Std.hx

@@ -50,7 +50,7 @@ import flash.Boot;
 	}
 	}
 
 
 	public static function random( x : Int ) : Int {
 	public static function random( x : Int ) : Int {
-		return untyped Math.floor(Math.random()*x);
+		return untyped x <= 0 ? 0 : Math.floor(Math.random()*x);
 	}
 	}
 
 
 	@:macro public static function format( fmt : haxe.macro.Expr.ExprOf<String> ) : haxe.macro.Expr.ExprOf<String> {
 	@:macro public static function format( fmt : haxe.macro.Expr.ExprOf<String> ) : haxe.macro.Expr.ExprOf<String> {

+ 1 - 1
std/js/_std/Std.hx

@@ -53,7 +53,7 @@ import js.Boot;
 	}
 	}
 
 
 	public static function random( x : Int ) : Int {
 	public static function random( x : Int ) : Int {
-		return untyped Math.floor(Math.random()*x);
+		return untyped x <= 0 ? 0 : Math.floor(Math.random()*x);
 	}
 	}
 
 
 	@:macro public static function format( fmt : haxe.macro.Expr.ExprOf<String> ) : haxe.macro.Expr.ExprOf<String> {
 	@:macro public static function format( fmt : haxe.macro.Expr.ExprOf<String> ) : haxe.macro.Expr.ExprOf<String> {

+ 1 - 1
std/php/_std/Std.hx

@@ -57,7 +57,7 @@
 	}
 	}
 
 
 	public static function random( x : Int ) : Int {
 	public static function random( x : Int ) : Int {
-		return untyped __call__("mt_rand", 0, x-1);
+		return untyped x <= 0 ? 0 : __call__("mt_rand", 0, x-1);
 	}
 	}
 
 
 	@:macro public static function format( fmt : haxe.macro.Expr.ExprOf<String> ) : haxe.macro.Expr.ExprOf<String> {
 	@:macro public static function format( fmt : haxe.macro.Expr.ExprOf<String> ) : haxe.macro.Expr.ExprOf<String> {