Sunday, 2 February 2014

Math object

The math object provides you properties and methods for mathematical constants and functions.
Unlike the other global objects, Math is not a constructor. All properties and methods of Math are static and can be called by using Math as an object without creating it.
Thus, you refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument.
Syntax:
Here is the simple syntax to call properties and methods of Math.
var pi_val = Math.PI;
var sine_val = Math.sin(30);
Math Properties:
Here is a list of each property and their description.
Property
Description
E
Euler's constant and the base of natural logarithms, approximately 2.718.
Natural logarithm of 2, approximately 0.693.
Natural logarithm of 10, approximately 2.302.
Base 2 logarithm of E, approximately 1.442.
Base 10 logarithm of E, approximately 0.434.
Ratio of the circumference of a circle to its diameter, approximately 3.14159.
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
Square root of 2, approximately 1.414.
Math Methods
Here is a list of each method and its description.
Method
Description
Returns the absolute value of a number.
Returns the arccosine (in radians) of a number.
Returns the arcsine (in radians) of a number.
Returns the arctangent (in radians) of a number.
Returns the arctangent of the quotient of its arguments.
Returns the smallest integer greater than or equal to a number.
Returns the cosine of a number.
Returns EN, where N is the argument, and E is Euler's constant, the base of the natural logarithm.
Returns the largest integer less than or equal to a number.
Returns the natural logarithm (base E) of a number.
Returns the largest of zero or more numbers.
Returns the smallest of zero or more numbers.
Returns base to the exponent power, that is, base exponent.
Returns a pseudo-random number between 0 and 1.
Returns the value of a number rounded to the nearest integer.
Returns the sine of a number.
Returns the square root of a number.
Returns the tangent of a number.
Returns the string "Math".


<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
 document.write(Math.max(6,8)+"<br/>");
 document.write(Math.min(6,8)+"<br/>");
 document.write("roound()"+Math.round(8.8)+"<br/>");
 document.write("floor()"+Math.floor(8.8)+"<br/>");
 document.write("ceil()"+Math.ceil(8.8)+"<br/>");
 document.write("random()"+Math.random()+"<br/>");
 document.write("sqrt()"+Math.sqrt(16)+"<br/>");
 document.write("PI"+Math.PI+"<br/>");  
 </script>
</body>
</html>



No comments:

Post a Comment