JavaScript对象之数学函数运算-Math

JavaScript封装了自己的函数库,下面来看看最常用的数学运算函数,以及封装使用的math.js工具包。

Math基本属性和方法



MathJs


官方网址:http://mathjs.org/

An extensive math library for JavaScript and Node.js

Math.js is an extensive math library for JavaScript and Node.js.It features a flexible expression parser and offers an integrated solutionto work with numbers, big numbers, complex numbers, units, and matrices.Powerful and easy to use.

Features

  • Supports numbers, big numbers, fractions, complex numbers, units, strings, arrays, and matrices.
  • Is compatible with JavaScript’s built-in Math library.
  • Contains a flexible expression parser.
  • Supports chained operations.
  • Comes with a large set of built-in functions and constants.
  • Has no dependencies. Runs on any JavaScript engine.
  • Is easily extensible.
  • Open source.
JS工具包引用示例:

<!DOCTYPE HTML>
<html>
<head>
  <script src="math.js" type="text/javascript"></script>
</head>
<body>
  <script type="text/javascript">
    // use math.js
    math.sqrt(-4); // 2i
  </script>
</body>
</html>


更多函数示例:

// 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.pow([[-1, 2], [3, 1]], 2);
     // [[7, 0], [0, 7]]

// expressions
math.eval('1.2 * (2 + 4.5)');     // 7.8
math.eval('5.08 cm to inch');     // 2 inch
math.eval('sin(45 deg) ^ 2');     // 0.5
math.eval('9 / 3 + 2i');          // 3 + 2i
math.eval('det([-1, 2; 3, 1])');  // -7

// chaining
math.chain(3)
    .add(4)
    .multiply(2)
    .done(); // 14



  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值