Math

Updated: 09/15/2017 by Computer Hope

mathMost computer programming languages provide a Math library which facilitates common or complicated mathematical operations. In object-oriented programming, it may take the form of an object with properties and methods to perform those functions. For instance, the JavaScript Math object provides constant values such as E (Euler's number), LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, and SQRT2. It also includes methods which allow the programmer to make mathematical calculations like square roots, rounding, trigonometry functions, and more.

In JavaScript, the Math object can be used directly to access on of its properties or methods, such as in the JavaScript code in the example below.

var x = 2 * Math.PI * 32;
var y = Math.sqrt(4);

The example shows the use of the PI property and a call to the sqrt() method.

Programming terms