You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
565 B
24 lines
565 B
const $math = require('mathjs')
|
|
export const math = {
|
|
add() {
|
|
return comp('add', arguments)
|
|
},
|
|
subtract() {
|
|
return comp('subtract', arguments)
|
|
},
|
|
multiply() {
|
|
return comp('multiply', arguments)
|
|
},
|
|
divide() {
|
|
return comp('divide', arguments)
|
|
}
|
|
}
|
|
|
|
function comp(_func, args) {
|
|
let t = $math.chain($math.bignumber(args[0]))
|
|
for (let i = 1; i < args.length; i++) {
|
|
t = t[_func]($math.bignumber(args[i]))
|
|
}
|
|
// 防止超过6位使用科学计数法
|
|
return parseFloat(t.done())
|
|
}
|
|
|