import Decimal from 'decimal.js';
// 加法
function add(...nums: number[]): number {
return nums.reduce((total, num) => new Decimal(total).plus(num), 0).toNumber();
}
// 减法
function subtract(...nums: number[]): number {
return nums.reduce((total, num) => new Decimal(total).minus(num)).toNumber();
}
// 乘法
function multiply(...nums: number[]): number {
return nums.reduce((total, num) => new Decimal(total).times(num), 1).toNumber();
}
// 除法
function divide(...nums: number[]): number {
return nums.reduce((total, num) => new Decimal(total).dividedBy(num)).toNumber();
}