OLPCities/Math (JavaScript)

From OLPC
Jump to: navigation, search

"Math" is a Class that is part of the generic JavaScript API. This "library" is referenced automaticaly by the browser of the OLPC station and you don't need to add anything in the program to use it.

In this Class you will not need to create an object, a prefix. The object is always : Math.

Using this Math prefix, the methods of the class are:

Methods

Math.abs(number)            Returns the absolute value of number. 

Math.ceil(number)           Returns the next largest  integer 
                            greater than number (rounds up).

Math.floor(number)          Returns the next smallest  integer 
                            less than the number (rounds down).

Math.pow(num1, num2)        Returns the value of num1 to the 
                            power of num2.

Math.random()               Returns a number between 0 and 1.

Math.round(number)          Returns the closest integer to the 
                            number

Math.sqrt(number)           Returns the square root of the number