main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
681 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var ToInt32 = require('./ToInt32');
|
---|
| 6 | var ToUint32 = require('./ToUint32');
|
---|
| 7 |
|
---|
| 8 | // https://262.ecma-international.org/11.0/#sec-numberbitwiseop
|
---|
| 9 |
|
---|
| 10 | module.exports = function NumberBitwiseOp(op, x, y) {
|
---|
| 11 | if (op !== '&' && op !== '|' && op !== '^') {
|
---|
| 12 | throw new $TypeError('Assertion failed: `op` must be `&`, `|`, or `^`');
|
---|
| 13 | }
|
---|
| 14 | if (typeof x !== 'number' || typeof y !== 'number') {
|
---|
| 15 | throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
|
---|
| 16 | }
|
---|
| 17 | var lnum = ToInt32(x);
|
---|
| 18 | var rnum = ToUint32(y);
|
---|
| 19 | if (op === '&') {
|
---|
| 20 | return lnum & rnum;
|
---|
| 21 | }
|
---|
| 22 | if (op === '|') {
|
---|
| 23 | return lnum | rnum;
|
---|
| 24 | }
|
---|
| 25 | return lnum ^ rnum;
|
---|
| 26 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.