summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/BigInt/constructor-integer.js
blob: c70dac79c6531e7ef2cf637b93be891112e1c134 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (C) 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: BigInt constructor called with integer argument
esid: sec-bigint-constructor-number-value
info: |
  BigInt ( value )

  ...
  3. If Type(prim) is Number, return ? NumberToBigInt(prim).

  NumberToBigInt ( number )

  ...
  3. Return a BigInt representing the mathematical value of number.
features: [BigInt]
---*/

assert.sameValue(
  BigInt(Number.MAX_SAFE_INTEGER), 9007199254740991n,
  "BigInt(Number.MAX_SAFE_INTEGER) === 9007199254740991n"
);

assert.sameValue(
  BigInt(-Number.MAX_SAFE_INTEGER), -9007199254740991n,
  "BigInt(-Number.MAX_SAFE_INTEGER) === -9007199254740991n"
);

assert.sameValue(
  BigInt(Number.MAX_SAFE_INTEGER + 1), 9007199254740992n,
  "BigInt(Number.MAX_SAFE_INTEGER + 1) === 9007199254740992n"
);

assert.sameValue(
  BigInt(-Number.MAX_SAFE_INTEGER - 1), -9007199254740992n,
  "BigInt(-Number.MAX_SAFE_INTEGER - 1) === -9007199254740992n"
);

assert.sameValue(
  BigInt(Number.MAX_SAFE_INTEGER + 2), 9007199254740992n,
  "BigInt(Number.MAX_SAFE_INTEGER + 2) === 9007199254740992n"
);

assert.sameValue(
  BigInt(-Number.MAX_SAFE_INTEGER - 2), -9007199254740992n,
  "BigInt(-Number.MAX_SAFE_INTEGER - 2) === -9007199254740992n"
);

assert.sameValue(
  BigInt(Number.MAX_SAFE_INTEGER + 3), 9007199254740994n,
  "BigInt(Number.MAX_SAFE_INTEGER + 3) === 9007199254740994n"
);

assert.sameValue(
  BigInt(-Number.MAX_SAFE_INTEGER - 3), -9007199254740994n,
  "BigInt(-Number.MAX_SAFE_INTEGER - 3) === -9007199254740994n"
);

reportCompare(0, 0);