Introduction to the properties and methods of math in JS

Source: Internet
Author: User
Tags natural logarithm square root

JS has a built-in object--math object, in some cases very useful, let us analyze:

Math Common Properties (note to capitalize):


e returns the arithmetic constant E, that is, the base of the natural logarithm (approximately equal to 2.718)
LN2 returns 2 of the natural logarithm (about 0.693)
LN10 returns 10 of the natural logarithm (about 2.302)
LOG2E returns the logarithm of the 2-based E (about 1.414)
LOG10E returns the logarithm of the 10-based E (about 0.434)
Pi returns PI (approximately equal to 3.14159)
Sqrt1_2 returns the reciprocal of the square root that returns 2 (approximately equal to 0.707)
SQRT2 returns the square root of 2 (approximately equal to 1.414)

Methods of the Math object

Absolute value of ABS (x) return number
ACOs (x) returns the inverse cosine of the number
ASIN (x) returns the inverse chord value of the number
Atan (x) returns the inverse tangent of x to the value between-PI/2 and PI/2 radians
ATAN2 (y,x) returns the angle (between-PI/2 and PI/2 radians) from the X axis to point (X,y)
Ceil (x) logarithm rounding
COS (x) returns the cosine of a number
EXP (x) returns the exponent of E
Floor (x) logarithmic rounding-– common
Log (x) returns the natural logarithm of the number (bottom e)
Max (X,y) returns the highest value in X and Y
MIN (x,y) returns the lowest value in X and Y
POW (x,y) returns the Y-power of X
Random () returns the random number between 0 ~ 1--Common
Round (x) rounding the number to the nearest integer
Sin (x) returns the sine of a number
SQRT (x) returns the square root of a number
Tan (x) returns the tangent of the angle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.