Reviewers: jarin,

Description:
Harmony: implement Math.log2 and Math.log10.

[email protected]
BUG=v8:2938

Please review this at https://codereview.chromium.org/119093006/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+32, -13 lines):
  M src/harmony-math.js
  A + test/mjsunit/harmony/math-log2-log10.js


Index: src/harmony-math.js
diff --git a/src/harmony-math.js b/src/harmony-math.js
index 2bf33d63f2c81b26263abffea9e931bb9a60008e..652e8aeb75db1757327a3044974a3ed79da48029 100644
--- a/src/harmony-math.js
+++ b/src/harmony-math.js
@@ -110,6 +110,18 @@ function MathAtanh(x) {
 }


+//ES6 draft 09-27-13, section 20.2.2.21.
+function MathLog10(x) {
+  return MathLog(x) * 0.434294481903251828;  // log10(x) = log(x)/log(10).
+}
+
+
+//ES6 draft 09-27-13, section 20.2.2.22.
+function MathLog2(x) {
+  return MathLog(x) * 1.442695040888963407;  // log2(x) = log(x)/log(2).
+}
+
+
 function ExtendMath() {
   %CheckIsBootstrapping();

@@ -122,7 +134,9 @@ function ExtendMath() {
     "tanh", MathTanh,
     "asinh", MathAsinh,
     "acosh", MathAcosh,
-    "atanh", MathAtanh
+    "atanh", MathAtanh,
+    "log10", MathLog10,
+    "log2", MathLog2
   ));
 }

Index: test/mjsunit/harmony/math-log2-log10.js
diff --git a/test/mjsunit/regress/regress-crbug-233737.js b/test/mjsunit/harmony/math-log2-log10.js
similarity index 68%
copy from test/mjsunit/regress/regress-crbug-233737.js
copy to test/mjsunit/harmony/math-log2-log10.js
index 38b44e056f24397d319d544f41afaea09b8b8d95..2ab496012cbe9785920b7f43f87f4bf571fcd435 100644
--- a/test/mjsunit/regress/regress-crbug-233737.js
+++ b/test/mjsunit/harmony/math-log2-log10.js
@@ -25,18 +25,23 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-// Flags: --allow-natives-syntax
+// Flags: --harmony-maths

-var a = new Array(2);
-a[0] = 1;
-assertTrue(%HasFastSmiElements(a));
-assertTrue(%HasFastHoleyElements(a));
+[Math.log10, Math.log2].forEach( function(fun) {
+  assertTrue(isNaN(fun(NaN)));
+  assertTrue(isNaN(fun(fun)));
+  assertTrue(isNaN(fun({ toString: function() { return NaN; } })));
+  assertTrue(isNaN(fun({ valueOf: function() { return -1; } })));
+  assertTrue(isNaN(fun({ valueOf: function() { return "abc"; } })));
+  assertTrue(isNaN(fun(-0.1)));
+  assertTrue(isNaN(fun(-1)));
+  assertEquals("-Infinity", String(fun(0)));
+  assertEquals("-Infinity", String(fun(-0)));
+  assertEquals(0, fun(1));
+  assertEquals("Infinity", String(fun(Infinity)));
+});

-function hole(i) {
-  return a[i] << 0;
+for (var i = -300; i < 300; i += 0.7) {
+  assertEqualsDelta(i, Math.log10(Math.pow(10, i)), 1E-13);
+  assertEqualsDelta(i, Math.log2(Math.pow(2, i)), 1E-13);
 }
-
-assertEquals(1, hole(0));
-assertEquals(1, hole(0));
-%OptimizeFunctionOnNextCall(hole);
-assertEquals(0, hole(1));


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to