{"id":318,"date":"2009-04-16T21:10:00","date_gmt":"2009-04-16T01:10:00","guid":{"rendered":""},"modified":"2013-11-29T14:10:43","modified_gmt":"2013-11-29T06:10:43","slug":"javascript%e7%9a%84%e6%95%b0%e5%ad%a6%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/318.html","title":{"rendered":"JavaScript\u7684\u6570\u5b66\u51fd\u6570"},"content":{"rendered":"<p>\u5728JavaScript\u4e2d\uff0c\u6570\u5b66\u65b9\u6cd5\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u7c7b\uff1aconstans\uff08\u5e38\u6570\uff09\u3001power functions\uff08\u4e58\u65b9\u51fd\u6570\uff09\u3001trigonometic functions\uff08\u4e09\u89d2\u51fd\u6570\uff09\u3001rounding functions\uff08\u820d\u5165\u51fd\u6570\uff09\u4ee5\u53carandom numbers\uff08\u968f\u673a\u6570\u5b57\uff09\u3002\u4e0b\u9762\u9010\u4e2a\u8bf4\u660e\uff1a<\/p>\n<p>\u5e38\u6570\u548c\u4e58\u65b9\u51fd\u6570<\/p>\n<p>Math.E<br \/>\n\u81ea\u7136\u5bf9\u6570\u7684\u5e95(\u4e3a\u5e38\u6570)<br \/>\n2.718<\/p>\n<p>Math.LN10<br \/>\n10\u7684\u81ea\u7136\u5bf9\u6570<br \/>\n2.302<\/p>\n<p>Math.LN2<br \/>\n2\u7684\u81ea\u7136\u5bf9\u6570<br \/>\n0.693<\/p>\n<p>Math.PI<br \/>\n\u5706\u5468\u7387<br \/>\n3.1415<\/p>\n<p>Math.SQRT1_2<br \/>\n1\/2\u7684\u5e73\u65b9\u6839<br \/>\n0.707<\/p>\n<p>Math.SQRT2<br \/>\n2\u7684\u5e73\u65b9\u6839<br \/>\n1.414<\/p>\n<p>Math.sqrt(x)<br \/>\nX\u7684\u5e73\u65b9\u6839<br \/>\n\u66f4X\u7684\u503c\u6709\u5173<\/p>\n<p>Math.pow(x, n)<br \/>\n\u8fd4\u56dex\u7684n\u6b21\u65b9\u7684\u6570\u503c<br \/>\n\u53c2\u6570\u4e3ax\u548cn<\/p>\n<p>Math.log(n)<br \/>\n\u8fd4\u56den\u7684\u81ea\u7136\u5bf9\u6570<br \/>\n\u53c2\u6570\u4e3an<\/p>\n<p>Math.exp(n)<br \/>\n\u8fd4\u56dee\u7684n\u6b21\u65b9\u7684\u6570\u503c<br \/>\n\u53c2\u6570\u4e3an<\/p>\n<p>\u4e09\u89d2\u51fd\u6570<\/p>\n<p>Math.cos(x)<br \/>\nX\u7684\u4f59\u5f26\u51fd\u6570<\/p>\n<p>Math.sin(x)<br \/>\nX\u7684\u6b63\u5f26\u51fd\u6570<\/p>\n<p>Math.tan(x)<br \/>\nX\u7684\u6b63\u5207\u51fd\u6570<\/p>\n<p>Math.acos(y)<br \/>\nX\u7684\u53cd\u4f59\u5f26\u51fd\u6570<\/p>\n<p>Math.asin(y)<br \/>\nX\u7684\u53cd\u6b63\u5f26\u51fd\u6570<\/p>\n<p>Math.atan(y)<br \/>\nX\u7684\u53cd\u6b63\u5207\u51fd\u6570<br \/>\n\u8fd9\u91cc\u6ce8\u610f\uff1a\u53c2\u6570x\u548c\u4ee5\u53ca\u53cd\u51fd\u6570\u7684\u8fd4\u56de\u6570\u503c\u7684\u5355\u4f4d\u90fd\u4e3a\u5f27\u5ea6\uff08\u6bd4\u5982 PI\u5f27\u5ea6=180\u5ea6\uff09<\/p>\n<p>\u820d\u5165\u51fd\u6570\u548c\u968f\u673a\u6570\u5b57<\/p>\n<p>Math.random()<br \/>\n\u4ea7\u751f\u4ece0\u52301\u7684\u968f\u673a\u6570<\/p>\n<p>Math.round(x)<br \/>\n\u53d6\u6700\u63a5\u8fd1\u6574\u6570x\u7684\u6570\u503c<\/p>\n<p>Math.floor(x)<br \/>\n\u53d6\u6700\u63a5\u8fd1\u6574\u6570x\u5e76\u4e14\u6bd4x\u5c0f\u7684\u6570\u503c<\/p>\n<p>Math.ceil(x)<br \/>\n\u53d6\u6700\u63a5\u8fd1\u6574\u6570x\u5e76\u4e14\u6bd4x\u5927\u7684\u6570\u503c<\/p>\n<p>Math.min(a, b, c)<br \/>\n\u8fd4\u56de\u53c2\u6570\u5217\u8868\u4e2d\u6700\u5c0f\u7684\u6570\u503c<\/p>\n<p>Math.max(a, b, c)<br \/>\n\u8fd4\u56de\u53c2\u6570\u5217\u8868\u4e2d\u6700\u5927\u7684\u6570\u503c<br \/>\n\u8fd9\u91cc\u6ce8\u610f\uff1a\u51fd\u6570Math.random()\u53ea\u80fd\u5728Unix\u7248\u672c\u7684Navigator 2.0\u6267\u884c\u3002<\/p>\n<p>\u8fd9\u4e9b\u51fd\u6570\u4e2d\u6700\u5e38\u7528\u7684\u5c31\u662f\u4ea7\u751f\u5728\u7ed9\u5b9a\u4e24\u4e2a\u6570\u503c\u4e4b\u95f4\u7684\u968f\u673a\u6570\u3002\u4ee5\u4e0b\u7684\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction randomvalue(low, high) {\r\n\r\nalert(Math.floor(Math.random() * (1 + high \u2013 low) + low));\r\n\r\n}\r\n<\/pre>\n<p>\u53e6\u5916\uff0c\u4f60\u53ef\u4ee5\u5728\u590d\u6742\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528with\u8bed\u53e5\u6765\u907f\u514dMath\u6807\u8bc6\u7b26\u7684\u91cd\u590d\u4f7f\u7528\uff0c\u4f8b\u5982\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction randomvalue(low, high) {\r\n\r\nwith (Math) {\r\n\r\nalert(floor(random() * (1 + high \u2013 low) + low));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p>\u8fd9\u91cc\u8981\u8bb0\u4f4f\uff0cMath.random()\u51fd\u6570\u53ea\u80fd\u5728Unix\u7248\u672c\u7684Navigator 2.0\u6267\u884c\uff0c\u800c\u4e0d\u80fd\u5728windows\u7248\u672c\u7684\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\uff0c\u6240\u4ee5\u8fd9\u4e2a\u51fd\u6570\u6211\u4eec\u4e00\u822c\u4e0d\u4f7f\u7528\u3002<\/p>\n<p>\u4ee5\u4e0b\u7ed9\u51fa\u7684\u662f\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de\u4e09\u89d2\u5f62\u7b2c\u4e09\u8fb9\u7684\u957f\u5ea6\uff0c\u7ed9\u51fa\u7684\u6761\u4ef6\u662f\u4e09\u89d2\u5f62\u7684\u4e24\u8fb9\u53ca\u4e24\u8fb9\u7684\u5939\u89d2\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction findside(sidea, sideb, angle) {\r\n\r\nwith (Math) {\r\n\r\nvar tmp = pow(sidea, 2) + pow(sideb, 2) \u2013 2 * sidea * sideb * cos(angle);\r\n\r\nalert(&quot;side length is &quot; + sqrt(tmp));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728JavaScript\u4e2d\uff0c\u6570\u5b66\u65b9\u6cd5\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u7c7b\uff1aconstans\uff08\u5e38\u6570\uff09\u3001power functions\uff08 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":5309,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions\/5309"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}