Math.js库的使用

Math.js库的使用

可以使用npm或Bower来安装Math.js,直接从Web网站下载,或者通过内容发布网络(CDN)来方法。它可以用于浏览器中,或者用于Node应用程序中。它提供了一组函数来执行操作,例如 add()和multiply()等,支持链化使用。
特征:

  1. Supports numbers, big numbers, complex numbers, fractions, units, strings, arrays, and matrices.
  2. Is compatible with JavaScript’s built-in Math library.
  3. Contains a flexible expression parser.
  4. Does symbolic computation.
  5. Comes with a large set of built-in functions and constants.
  6. Has no dependencies. Runs on any JavaScript engine.
  7. Can be used as a command line application as well.
  8. Is easily extensible.
  9. Open source.
<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="math.js | basic usage">
  <title>math.js | basic usage</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.14.2/math.min.js"></script>
</head>
<body>
  <script>
    // functions and constants
    print(math.round(math.e, 3));            // 2.718
    print(math.atan2(3, -3) / math.pi);      // 0.75
    print(math.log(10000, 10));              // 4
    print(math.sqrt(-4));                    // 2i
    print(math.pow([[-1, 2], [3, 1]], 2));   // [[7, 0], [0, 7]]
    print(math.derivative('x^2 + x', 'x'));  // 2 * x + 1

    // expressions
    print(math.eval('12 / (2.3 + 0.7)'));    // 4
    print(math.eval('12.7 cm to inch'));     // 5 inch
    print(math.eval('9 / 3 + 2i'));          // 3 + 2i
    print(math.eval('det([-1, 2; 3, 1])'));  // -7

    // chaining
    var a = math.chain(3)
        .add(4)
        .multiply(2)
        .done();
    print(a); // 14

    // helper function to output formatted results.
    function print(value) {
      var precision = 14;
      document.write(math.format(value, precision) + '<br>');
    }
  </script>
</body>
</html>

下载网站
+ website: http://mathjs.org
+ docs: http://mathjs.org/docs
+ examples: http://mathjs.org/examples

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值