Baseline Widely available *
Math
æ¯ä¸åæææ¸å¸å¸¸æ¸åæ¸å¸å½æ¸ï¼éå½å¼ç©ä»¶ï¼å±¬æ§åæ¹æ³çå
§å»ºç©ä»¶ã
ä¸åå
¶ä»çå
¨åç©ä»¶ï¼Math
並é建æ§å½å¼ãææ Math
ç屬æ§åæ¹æ³ççºéæ
ãä½ å¯ä»¥ä½¿ç¨ Math.PI
ä¾åèå°åå¨ç pi ç常æ¸å¼ï¼ä»¥åå¯ä»¥å¼å« Math.sin(x)
å½å¼ä¾è¨ç®ä¸è§å½æ¸æ£å¼¦æ²ç· sineï¼x
çºæ¹æ³ç弿¸ï¼ãå¸¸æ¸æ¯ç± JavaScript ä¸å¯¦æ¸ç宿´ç²¾åº¦ä¾å®ç¾©ã
Math.E
ææå¸¸æ¸ (æ¤æèªç¶å¸¸æ¸) ï¼ä¹æ¯èªç¶å°æ¸çåºæ¸ï¼ç´çº 2.718ã
Math.LN2
2 çèªç¶å°æ¸ï¼ç´çº 0.693ã
Math.LN10
10 çèªç¶å°æ¸ï¼ç´çº 2.303ã
Math.LOG2E
以 2 çºåºç E çå°æ¸ï¼ç´çº 1.443ã
Math.LOG10E
以 10 çºåºç E çå°æ¸ï¼ç´çº 0.434ã
Math.PI
ä¸ååçåå¨åå ¶ç´å¾æ¯å¼ï¼ç´çº 3.14159ã
Math.SQRT1_2
1/2 çå¹³æ¹æ ¹ï¼ä¹å°±æ¯ 1 é¤ä»¥ 2 çå¹³æ¹æ ¹ï¼ç´çº 0.707ã
Math.SQRT2
2 çå¹³æ¹æ ¹ï¼ç´çº 1.414ã
åè¨»ï¼ ä¸è§å½æ¸ (sin()
, cos()
, tan()
, asin()
, acos()
, atan()
, atan2()
) ç忏æåå³å¼çè§åº¦ç以弧度çºå®ä½ãæè§åº¦ä¹ä¸ (Math.PI / 180)
æå¾å°å¼§åº¦å®ä½ï¼å°å¼§åº¦é¤ä»¥è©²æ¸åæè½æåä¸è¬æç¨çè§åº¦å®ä½ã
åè¨»ï¼ è¨±å¤æ¸å¸æ¹æ³ç精度æ¯å決æ¼å¯¦ä½æ¹å¼çãéæå³èä¸åçç覽å¨å¯è½æå¾å°ä¸åççµæï¼çè³åä¸å JS 弿å¨ä¸åç使¥ç³»çµ±ææ¶æ§ä¸æå¾å°ççµæé½æå¯è½ç¸ç°ã
Math.abs(x)
åå³ x ççµå°å¼ã
Math.acos(x)
åå³ x çåé¤å¼¦å¼ã
Math.acosh(x)
Returns the hyperbolic arccosine of a number.
Math.asin(x)
åå³ x ç忣弦å¼ã
Math.asinh(x)
Returns the hyperbolic arcsine of a number.
Math.atan(x)
åå³ x ç忣åå¼ã
Math.atanh(x)
Returns the hyperbolic arctangent of a number.
Math.atan2(y, x)
Returns the arctangent of the quotient of its arguments.
Math.cbrt(x)
åå³ x çç«æ¹æ ¹å¼ã
Math.ceil(x)
åå³ä¸å°æ¼ x çæå°æ´æ¸å¼ã
Math.clz32(x)
Returns the number of leading zeroes of a 32-bit integer.
Math.cos(x)
åå³ x çé¤å¼¦å¼ã
Math.cosh(x)
Returns the hyperbolic cosine of a number.
Math.exp(x)
åå³ E^xï¼x çºçµ¦å®æ¸å¼ï¼E çºææå¸¸æ¸ (èªç¶å°æ¸çåºæ¸)ã
Math.expm1(x)
åå³ exp(x)
æ¸å» 1 çå¼ã
Math.floor(x)
åå³ä¸å¤§æ¼ x çæå¤§æ´æ¸å¼ã
Math.fround(x)
Returns the nearest single precision float representation of a number.
Math.hypot([x[, y[, â¦]]])
åå³åæ¸å¹³æ¹ä¹åçå¹³æ¹æ ¹ã
Math.imul(x, y)
Returns the result of a 32-bit integer multiplication.
Math.log(x)
åå³ x çèªç¶å°æ¸å¼ã
Math.log1p(x)
åå³ 1 + x
çèªç¶å°æ¸å¼ã
Math.log10(x)
åå³ä»¥ 10 çºåºï¼x çå°æ¸å¼ã
Math.log2(x)
åå³ä»¥ 2 çºåºï¼x çå°æ¸å¼ã
Math.max([x[, y[, â¦]]])
åå³çµ¦å®æ¸å¼ä¸çæå¤§å¼ã
Math.min([x[, y[, â¦]]])
åå³çµ¦å®æ¸å¼ä¸çæå°å¼ã
Math.pow(x, y)
åå³ x ç y 次æ¹ï¼ä¹å°±æ¯ x^y
ã
Math.random()
åå³ä¸å 0 å° 1 ä¹éçå½é¨æ©å¼ã
Math.round(x)
åå³ x ç忍äºå ¥å¼ã
Math.sign(x)
åå³ x çæ£è² èï¼ä¹å°±æ¯åå³ x çæ£è² ã
Math.sin(x)
åå³ x çæ£å¼¦å¼ã
Math.sinh(x)
Returns the hyperbolic sine of a number.
Math.sqrt(x)
åå³ x çæ£å¹³æ¹æ ¹ã
Math.tan(x)
åå³ x çæ£åå¼ã
Math.tanh(x)
Returns the hyperbolic tangent of a number.
Math.toSource()
Non-standard
åå³å串 "Math"
ã
Math.trunc(x)
Returns the integral part of the number x, removing any fractional digits.
Math
ç©ä»¶
As most of the built-in objects in JavaScript, the Math
object can be extended with custom properties and methods. To extend the Math
object, you do not use 'prototype'. Instead, you directly extend Math
:
Math.propName = propValue; Math.methodName = methodRef;
For instance, the following example adds a method to the Math
object for calculating the greatest common divisor of a list of arguments.
/* Variadic function -- Returns the greatest common divisor of a list of arguments */
Math.gcd = function () {
if (arguments.length == 2) {
if (arguments[1] == 0) return arguments[0];
else return Math.gcd(arguments[1], arguments[0] % arguments[1]);
} else if (arguments.length > 2) {
var result = Math.gcd(arguments[0], arguments[1]);
for (var i = 2; i < arguments.length; i++)
result = Math.gcd(result, arguments[i]);
return result;
}
};
Try it:
console.log(Math.gcd(20, 30, 15, 70, 40)); // `5`
è¦ç¯ ç覽å¨ç¸å®¹æ§ åè¦
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4