summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/es6/math-clz32.js
blob: 3cbd4c3fccdef960cd512f43bb0119e4c6254ecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

[NaN, Infinity, -Infinity, 0, -0, "abc", "Infinity", "-Infinity", {}].forEach(
  function(x) {
    assertEquals(32, Math.clz32(x));
  }
);

function testclz(x) {
  for (var i = 0; i < 33; i++) {
    if (x & 0x80000000) return i;
    x <<= 1;
  }
  return 32;
}


function f(e) {
  var max = Math.pow(2, e);
  for (var x = 0; x < max; x = x * 1.01 + 1) {
    assertEquals(testclz(x), Math.clz32(x));
    assertEquals(testclz(-x), Math.clz32(-x));
    assertEquals(testclz(x), Math.clz32({ valueOf: function() { return x; } }));
    assertEquals(testclz(-x),
                 Math.clz32({ toString: function() { return -x; } }));
  }
}

f(5);
f(5);
%OptimizeFunctionOnNextCall(f);
f(40);