2
0
Эх сурвалжийг харах

Adding log base to hxd/Math.hx

clementlandrin 3 сар өмнө
parent
commit
1659c5d00a
1 өөрчлөгдсөн 9 нэмэгдсэн , 1 устгасан
  1. 9 1
      hxd/Math.hx

+ 9 - 1
hxd/Math.hx

@@ -36,7 +36,7 @@ class Math {
 			neg = 1.0;
 		if( std.Math.isNaN(v) || !std.Math.isFinite(v) )
 			return v;
-		var digits = Std.int(4 - std.Math.log(v) / std.Math.log(10));
+		var digits = Std.int(4 - logBase(v, 10));
 		if( digits < 1 )
 			digits = 1;
 		else if( digits >= 10 )
@@ -45,6 +45,14 @@ class Math {
 		return std.Math.ffloor(v * exp + .49999) * neg / exp;
 	}
 
+	public static inline function log( f : Float ) {
+		return std.Math.log(f);
+	}
+
+	public static inline function logBase( f : Float, base : Float ) {
+		return log(f) / log(base);
+	}
+
 	public static inline function floor( f : Float ) {
 		return std.Math.floor(f);
 	}