关键词搜索

源码搜索 ×
×

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

发布2016-08-23浏览6501次

详情内容

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工具包引用示例:

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <script src="math.js" type="text/javascript"></script>
  5. </head>
  6. <body>
  7. <script type="text/javascript">
  8. // use math.js
  9. math.sqrt(-4); // 2i
  10. </script>
  11. </body>
  12. </html>

更多函数示例:

  1. // functions and constants
  2. math.round(math.e, 3); // 2.718
  3. math.atan2(3, -3) / math.pi; // 0.75
  4. math.log(10000, 10); // 4
  5. math.sqrt(-4); // 2i
  6. math.pow([[-1, 2], [3, 1]], 2);
  7. // [[7, 0], [0, 7]]
  8. // expressions
  9. math.eval('1.2 * (2 + 4.5)'); // 7.8
  10. math.eval('5.08 cm to inch'); // 2 inch
  11. math.eval('sin(45 deg) ^ 2'); // 0.5
  12. math.eval('9 / 3 + 2i'); // 3 + 2i
  13. math.eval('det([-1, 2; 3, 1])'); // -7
  14. // chaining
  15. math.chain(3)
  16. .add(4)
  17. .multiply(2)
  18. .done(); // 14


相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载