| 1 |
// Copyright (C) 2016 The V8 Project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
es6id: 20.2.2.11 |
| 6 |
esid: sec-math.clz32 |
| 7 |
description: > |
| 8 |
Catches the int32bit value in the ToUint32 operation |
| 9 |
info: | |
| 10 |
Math.clz32 ( x ) |
| 11 |
|
| 12 |
1. Let n be ToUint32(x). |
| 13 |
2. Let p be the number of leading zero bits in the 32-bit binary representation of n. |
| 14 |
3. Return p. |
| 15 |
|
| 16 |
7.1.6 ToUint32 ( argument ) |
| 17 |
|
| 18 |
[...] |
| 19 |
3. Let int be the mathematical value that is the same sign as number and whose |
| 20 |
magnitude is floor(abs(number)). |
| 21 |
4. Let int32bit be int modulo 232. |
| 22 |
5. Return int32bit. |
| 23 |
[...] |
| 24 |
---*/ |
| 25 |
|
| 26 |
assert.sameValue(Math.clz32(4294967295), 0, "2**32-1"); |
| 27 |
assert.sameValue(Math.clz32(4294967296), 32, "2**32"); |
| 28 |
assert.sameValue(Math.clz32(4294967297), 31, "2**32+1"); |
| 29 |
|
| 30 |
assert.sameValue(Math.clz32(65535), 16, "2**16-1"); |
| 31 |
assert.sameValue(Math.clz32(65536), 15, "2**16"); |
| 32 |
assert.sameValue(Math.clz32(65537), 15, "2**16+1"); |
| 33 |
|
| 34 |
assert.sameValue(Math.clz32(255), 24, "2**8-1"); |
| 35 |
assert.sameValue(Math.clz32(256), 23, "2**8"); |
| 36 |
assert.sameValue(Math.clz32(257), 23, "2**8+1"); |
| 37 |
|
| 38 |
assert.sameValue(Math.clz32(-4294967295), 31, "-(2**32-1)"); |
| 39 |
assert.sameValue(Math.clz32(-4294967296), 32, "-(2**32)"); |
| 40 |
assert.sameValue(Math.clz32(-4294967297), 0, "-(2**32+1)"); |
| 41 |
|
| 42 |
assert.sameValue(Math.clz32(-65535), 0, "-(2**16-1)"); |
| 43 |
assert.sameValue(Math.clz32(-65536), 0, "-(2**16)"); |
| 44 |
assert.sameValue(Math.clz32(-65537), 0, "-(2**16+1)"); |
| 45 |
|
| 46 |
assert.sameValue(Math.clz32(-255), 0, "-(2**8-1)"); |
| 47 |
assert.sameValue(Math.clz32(-256), 0, "-(2**8)"); |
| 48 |
assert.sameValue(Math.clz32(-257), 0, "-(2**8+1)"); |