UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

25 lines (23 loc) 521 B
'use strict'; /** * Bitwise not * @param {BigNumber} x * @return {BigNumber} Result of ~`x`, fully precise * */ module.exports = function bitNot(x) { if (x.isFinite() && !x.isInteger()) { throw new Error('Integer expected in function bitNot'); } var BigNumber = x.constructor; var prevPrec = BigNumber.precision; BigNumber.config({ precision: 1E9 }); var result = x.plus(new BigNumber(1)); result.s = -result.s || null; BigNumber.config({ precision: prevPrec }); return result; };