2024-05-07 11:51:58 +08:00
|
|
|
//封装
|
|
|
|
import { Decimal } from 'decimal.js'
|
2024-05-07 11:30:13 +08:00
|
|
|
|
2024-05-07 11:51:58 +08:00
|
|
|
// 加
|
|
|
|
export function add (x, y) {
|
|
|
|
if (!x) {
|
|
|
|
x = 0
|
|
|
|
}
|
|
|
|
if (!y) {
|
|
|
|
y = 0
|
|
|
|
}
|
|
|
|
const xx = new Decimal(x)
|
|
|
|
const yy = new Decimal(y)
|
|
|
|
return xx.plus(yy).toNumber()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 减
|
|
|
|
export function reduce (x, y) {
|
|
|
|
if (!x) {
|
|
|
|
x = 0
|
|
|
|
}
|
|
|
|
if (!y) {
|
|
|
|
y = 0
|
|
|
|
}
|
|
|
|
const xx = new Decimal(x)
|
|
|
|
const yy = new Decimal(y)
|
|
|
|
return xx.minus(yy).toNumber()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 乘
|
|
|
|
export function ride (x, y) {
|
|
|
|
if (!x) {
|
|
|
|
x = 0
|
|
|
|
}
|
|
|
|
if (!y) {
|
|
|
|
y = 0
|
|
|
|
}
|
|
|
|
const xx = new Decimal(x)
|
|
|
|
const yy = new Decimal(y)
|
|
|
|
return xx.mul(yy).toNumber()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 除
|
|
|
|
export function except (x, y) {
|
|
|
|
if (!x) {
|
|
|
|
x = 0
|
|
|
|
}
|
|
|
|
if (!y) {
|
|
|
|
y = 0
|
|
|
|
}
|
|
|
|
const xx = new Decimal(x)
|
|
|
|
const yy = new Decimal(y)
|
|
|
|
return xx.div(yy).toNumber()
|
2024-05-07 11:30:13 +08:00
|
|
|
}
|