保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
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
61
62
63
64
65
66
'use strict';
 
var GetIntrinsic = require('get-intrinsic');
 
var $TypeError = GetIntrinsic('%TypeError%');
// var $BigInt = GetIntrinsic('%BigInt%', true);
// var $pow = GetIntrinsic('%Math.pow%');
 
// var BinaryAnd = require('./BinaryAnd');
// var BinaryOr = require('./BinaryOr');
// var BinaryXor = require('./BinaryXor');
var Type = require('./Type');
// var modulo = require('./modulo');
 
// var zero = $BigInt && $BigInt(0);
// var negOne = $BigInt && $BigInt(-1);
// var two = $BigInt && $BigInt(2);
 
// https://262.ecma-international.org/11.0/#sec-bigintbitwiseop
 
module.exports = function BigIntBitwiseOp(op, x, y) {
    if (op !== '&' && op !== '|' && op !== '^') {
        throw new $TypeError('Assertion failed: `op` must be `&`, `|`, or `^`');
    }
    if (Type(x) !== 'BigInt' || Type(y) !== 'BigInt') {
        throw new $TypeError('`x` and `y` must be BigInts');
    }
 
    if (op === '&') {
        return x & y;
    }
    if (op === '|') {
        return x | y;
    }
    return x ^ y;
    /*
    var result = zero;
    var shift = 0;
    while (x !== zero && x !== negOne && y !== zero && y !== negOne) {
        var xDigit = modulo(x, two);
        var yDigit = modulo(y, two);
        if (op === '&') {
            result += $pow(2, shift) * BinaryAnd(xDigit, yDigit);
        } else if (op === '|') {
            result += $pow(2, shift) * BinaryOr(xDigit, yDigit);
        } else if (op === '^') {
            result += $pow(2, shift) * BinaryXor(xDigit, yDigit);
        }
        shift += 1;
        x = (x - xDigit) / two;
        y = (y - yDigit) / two;
    }
    var tmp;
    if (op === '&') {
        tmp = BinaryAnd(modulo(x, two), modulo(y, two));
    } else if (op === '|') {
        tmp = BinaryAnd(modulo(x, two), modulo(y, two));
    } else {
        tmp = BinaryXor(modulo(x, two), modulo(y, two));
    }
    if (tmp !== 0) {
        result -= $pow(2, shift);
    }
    return result;
    */
};