1 | 'use strict'
|
2 | const bitwise = require('./bitwise')
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | module.exports = function bitOr (x, y) {
|
25 | if ((x.isFinite() && !x.isInteger()) || (y.isFinite() && !y.isInteger())) {
|
26 | throw new Error('Integers expected in function bitOr')
|
27 | }
|
28 |
|
29 | const BigNumber = x.constructor
|
30 | if (x.isNaN() || y.isNaN()) {
|
31 | return new BigNumber(NaN)
|
32 | }
|
33 |
|
34 | const negOne = new BigNumber(-1)
|
35 | if (x.isZero() || y.eq(negOne) || x.eq(y)) {
|
36 | return y
|
37 | }
|
38 | if (y.isZero() || x.eq(negOne)) {
|
39 | return x
|
40 | }
|
41 |
|
42 | if (!x.isFinite() || !y.isFinite()) {
|
43 | if ((!x.isFinite() && !x.isNegative() && y.isNegative()) ||
|
44 | (x.isNegative() && !y.isNegative() && !y.isFinite())) {
|
45 | return negOne
|
46 | }
|
47 | if (x.isNegative() && y.isNegative()) {
|
48 | return x.isFinite() ? x : y
|
49 | }
|
50 | return x.isFinite() ? y : x
|
51 | }
|
52 |
|
53 | return bitwise(x, y, function (a, b) { return a | b })
|
54 | }
|