Appearance
自定义使用
创建实例
javascript
const { create, all } = require('mathjs');
const math = create(all, {
number: 'BigNumber',
precision: 64
});例子
javascript
// 计算除法
const start = Date.now();
const result = math.evaluate("1 / 3");
const end = Date.now();
console.log('1/3 =', result, '耗时', end - start, 'ms秒');
const start1 = Date.now();
const result1 = math.evaluate("1 / 3 * 3");
const end1 = Date.now();
console.log('1/3 * 3 =', result1, '耗时', end1 - start1, 'ms秒');
const start2 = Date.now();
const result2 = math.evaluate("1 / 3");
const result3 = math.multiply(result2, 3);
const end2 = Date.now();
console.log('1/3 multiply 3 =', result3, '耗时', end2 - start2, 'ms秒');结果
txt
1/3 = 0.3333333333333333333333333333333333333333333333333333333333333333 耗时 43 ms秒
1/3 * 3 = 0.9999999999999999999999999999999999999999999999999999999999999999 耗时 1 ms秒
1/3 multiply 3 = 0.9999999999999999999999999999999999999999999999999999999999999999 耗时 1 ms秒