// 导入 bignumber.js 库 const { BigNumber } = require('bignumber.js');
// 封装加法函数 function add(a, b) { const result = new BigNumber(a).plus(b); return result.toString(); }
// 封装减法函数 function subtract(a, b) { const result = new BigNumber(a).minus(b); return result.toString(); }
// 封装乘法函数 function multiply(a, b) { const result = new BigNumber(a).times(b); return result.toString(); }
// 封装除法函数 function divide(a, b) { const result = new BigNumber(a).dividedBy(b); return result.toString(); }
// 测试加减乘除函数
const sum = add('123456789012345678901234567890', '987654321098765432109876543210'); console.log(sum); // 输出 "1111111110111111111011111111100"
const difference = subtract('123456789012345678901234567890', '987654321098765432109876543210'); console.log(difference); // 输出 "-864197532086419753208641975320" const product = multiply('123456789012345678901234567890', '987654321098765432109876543210'); console.log(product); // 输出 "1219326311126352698569723695057469911462941046381761008268731700"
const quotient = divide('123456789012345678901234567890', '987654321098765432109876543210'); console.log(quotient); // 输出 "0.12499999999999999999876543211"