JavaScript DHTML/Javascript Objects/Math
Содержание
- 1 "abs()" Example
- 2 "acos()" Example
- 3 "asin()" Example
- 4 "atan2()" Example
- 5 "atan()" Example
- 6 "ceil()" Example
- 7 "cos()" Example
- 8 "E" Example
- 9 "exp()" Example
- 10 "floor()" Example
- 11 "isNaN()" Example
- 12 "LN10" Example
- 13 "LN2" Example
- 14 "LOG10E" Example
- 15 "LOG2E" Example
- 16 "log()" Example
- 17 Math functions
- 18 "max()" Example
- 19 "MAX_VALUE" Example
- 20 "min()" Example
- 21 "MIN_VALUE" Example
- 22 "NEGATIVE_INFINITY" Example
- 23 "parseFloat()" Example
- 24 "parseInt()" Example
- 25 "PI" Example
- 26 "POSITIVE_INFINITY" Example
- 27 "pow()" Example
- 28 "round()" Example
- 29 "sin()" Example
- 30 "SQRT1_2" Example
- 31 "SQRT2" Example
- 32 "sqrt()" Example
- 33 "tan()" Example
"abs()" Example
<html>
<body>
<button onclick="alert(Math.abs(-10));">Math.abs(-10)</button>
</body>
</html>
"acos()" Example
<html>
<body>
<button onclick="alert(Math.acos(1));">Math.acos(1)</button>
</body>
</html>
"asin()" Example
<html>
<body>
<button onclick="alert(Math.asin(1));">Math.asin(1)</button>
</body>
</html>
"atan2()" Example
<html>
<body>
<button onclick="alert(Math.atan2(1,1));">Math.atan2(1,1)</button>
</body>
</html>
"atan()" Example
<html>
<body>
<button onclick="alert(Math.atan(1));">Math.atan(1)</button>
</body>
</html>
"ceil()" Example
<html>
<body>
<button onclick="alert(Math.ceil(1.1));">Math.ceil(1.1): CEIL</button>
</body>
</html>
"cos()" Example
<html>
<body>
<button onclick="alert(Math.cos(1));">Math.cos(1)</button>
</body>
</html>
"E" Example
<html>
<body>
<button onclick="alert(Math.E);">Math.E</button>
</body>
</html>
"exp()" Example
<html>
<body>
<button onclick="alert(Math.exp(1));">Math.exp(1)</button>
</body>
</html>
"floor()" Example
<html>
<body>
<button onclick="alert(Math.floor(1.1));">Math.floor(1.1)</button>
</body>
</html>
"isNaN()" Example
<html>
<body>
<button onclick="alert(isNaN("12.34"));">isNaN("12.34") True</button>
<button onclick="alert(isNaN("Hello"));">isNaN("Hello") False</button>
</body>
</html>
"LN10" Example
<html>
<body>
<button onclick="alert(Math.LN2);">Math.LN2</button>
</body>
</html>
"LN2" Example
<html>
<body>
<button onclick="alert(Math.LN10);">Math.LN10</button>
</body>
</html>
"LOG10E" Example
<html>
<body>
<button onclick="alert(Math.LOG10E);">Math.Log10E</button>
</body>
</html>
"LOG2E" Example
<html>
<body>
<button onclick="alert(Math.LOG2E);">Math.Log2E</button>
</body>
</html>
"log()" Example
<html>
<body>
<button onclick="alert(Math.log(1));">Math.log(1)</button>
</body>
</html>
Math functions
Math Description Methods
abs(x) Returns the absolute value of x.
acos(x) Returns the arc cosine of x in radians.
asin(x) Returns the arc sine of x in radians.
atan(x) Returns the arc tangent of x in radians.
atan2(y,x) Returns the arc tangent of the quotient of its Arguments, that is, y/x.
ceil(x) Returns the smallest integer greater than or equal to x.
cos(x) Returns the cosine of x.
exp(x) Returns ex, where x is the Argument and e is Euler"s constant.
floor(x) Returns the largest integer less than or equal to x.
log(x) Returns the natural logarithm (base E) of x.
max(x,y) Returns the greater of the two numbers x and y.
min(x,y) Returns the lesser of the two numbers x and y.
pow(x,y) Returns xy, traditionally base to the exponent power, that is, baseexponent.
random() Returns a pseudo-random number between 0 and 1.
round(x) Returns the value of x rounded to the nearest integer with .50 as cutoff.
sin(x) Returns the sine of x.
sqrt(x) Returns the square root of x.
tan(x) Returns the tangent of x.
"max()" Example
<html>
<body>
<button onclick="alert(Math.max(1, 2));">Math.max(1, 2)</button>
</body>
</html>
"MAX_VALUE" Example
<html>
<body>
<button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button>
<button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button>
<button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button>
<button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button>
</body>
</html>
"min()" Example
<html>
<body>
<button onclick="alert(Math.min(1, 2));">Math.min(1, 2)</button>
</body>
</html>
"MIN_VALUE" Example
<html>
<body>
<button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button>
<button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button>
<button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button>
<button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button>
</body>
</html>
"NEGATIVE_INFINITY" Example
<html>
<body>
<button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button>
<button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button>
<button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button>
<button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button>
</body>
</html>
"parseFloat()" Example
<html>
<body>
<button onclick="alert(parseFloat("12.34"));">parseFloat("12.34")</button>
<button onclick="alert(parseFloat("Hello"));">parseFloat("Hello")</button>
</body>
</html>
"parseInt()" Example
<html>
<body>
<button onclick="alert(parseInt("12.34"));">parseInt("12.34")</button>
<button onclick="alert(parseInt("Hello"));">parseInt("Hello")</button>
</body>
</html>
"PI" Example
<html>
<body>
<button onclick="alert(Math.PI);">Math.PI</button>
</body>
</html>
"POSITIVE_INFINITY" Example
<html>
<body>
<button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button>
<button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button>
<button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button>
<button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button>
</body>
</html>
"pow()" Example
<html>
<body>
<button onclick="alert(Math.pow(2,2));">Math.pow(2,2)</button>
</body>
</html>
"round()" Example
<html>
<body>
<button onclick="alert(Math.round(1.33));">Math.round(1.33)</button>
</body>
</html>
"sin()" Example
<html>
<body>
<button onclick="alert(Math.sin(1));">Math.sin(1)</button>
</body>
</html>
"SQRT1_2" Example
<html>
<body>
<button onclick="alert(Math.SQRT1_2);">Math.Sqrt1_2</button>
</body>
</html>
"SQRT2" Example
<html>
<body>
<button onclick="alert(Math.SQRT2);">Math.Sqrt2</button>
</body>
</html>
"sqrt()" Example
<html>
<body>
<button onclick="alert(Math.sqrt(2));">Math.sqrt(2)</button>
</body>
</html>
"tan()" Example
<html>
<body>
<button onclick="alert(Math.tan(1));">Math.tan(1) = ? </button>
</body>
</html>