MathX
具有链式API的灵活数学工具。
constructor(value?: number, precision?: number, rounding?: "half-up" | "up" | "down")
value
: 初始值。默认为 0
。precision
: 小数位数。默认为 2
。rounding
: 舍入模式。默认为 'half-up'
。MathX
实例。set(value: number): this
value
: 新的值。value(): number
setPrecision(digits: number): this
digits
: 小数位数。setRounding(mode: "half-up" | "up" | "down"): this
mode
: 舍入模式 ('half-up'
, 'up'
, 'down'
)。clone(value?: number): MathX
value
: 可选的新值。MathX
实例。add(num: number): this
num
: 要相加的数字。subtract(num: number): this
num
: 要相减的数字。multiply(num: number): this
num
: 要相乘的数字。divide(num: number): this
num
: 除数。num
为 0
。abs(): this
sqrt(): this
cbrt(): this
pow(exp: number): this
exp
: 指数。floor(): this
ceil(): this
round(): this
sign(): this
degToRad(): this
radToDeg(): this
max(...nums: number[]): this
nums
: 要比较的数字。min(...nums: number[]): this
nums
: 要比较的数字。sin(): this
cos(): this
tan(): this
asin(): this
acos(): this
atan(): this
log(): this
log10(): this
exp(): this
toExponential(fractionDigits?: number): string
fractionDigits
: 小数点后的位数。如果省略,则使用必要的位数。