Appearance
首页
适用于 JavaScript 和 Node.js 的广泛数学库
Math.js 是一个用于 JavaScript 和 Node.js 的广泛数学库。它具有一个灵活的表达式解析器,支持符号计算,带有大量内置函数和常量,并提供一个集成解决方案来处理不同的数据类型,如数字、大数、复数、分数、单位和矩阵。功能强大且易于使用。
特征
- 支持数字、大数、bigint、复数、分数、单位、字符串、数组和矩阵
- 与 JavaScript 的内置数学库兼容。
- 包含灵活的表达式解析器。
- 执行符号计算。
- 附带大量内置函数和常量。
- 也可以用作命令行应用程序。
- 可在任何 JavaScript 引擎上运行。
- 易于扩展。
- 开源。
示例
下面是一些示例代码,演示如何使用该库。点击这里摆弄。
js
// functions and constants
math.round(math.e, 3) // 2.718
math.atan2(3, -3) / math.pi // 0.75
math.log(10000, 10) // 4
math.sqrt(-4) // 2i
math.derivative('x^2 + x', 'x') // 2*x+1
math.pow([[-1, 2], [3, 1]], 2)
// [[7, 0], [0, 7]]
// expressions
math.evaluate('1.2 * (2 + 4.5)') // 7.8
math.evaluate('12.7 cm to inch') // 5 inch
math.evaluate('sin(45 deg) ^ 2') // 0.5
math.evaluate('9 / 3 + 2i') // 3 + 2i
math.evaluate('det([-1, 2; 3, 1])') // -7
// chaining
math.chain(3)
.add(4)
.multiply(2)
.done() // 14
演示
请尝试下面的表达式解析器。
有关完整的应用程序,请参阅 Math Notepad。
js
1.2 / (3.3 + 1.7)
0.24
a = 5.08 cm + 2 inch
10.16 cm
a to inch
4 inch
sin(90 deg)
1
f(x, y) = x ^ y
f(x, y)
f(2, 3)
8