Mathematical functions in Javascript

Source: Internet
Author: User
Tags mathematical functions natural logarithm

In JavaScript, mathematical methods can be divided into the following types:
Constans (constant), power functions (multiplication function), trigonometic functions (trigonometric function), rounding functions (rounding function), random numbers (random number)

Constants and multiplication Functions

Math. e Base of natural logarithm (constant) 2.718
Math. ln10 Natural logarithm of 10 2.302
Math. ln2 Natural logarithm of 2 0.693
Math. Pi Circumference Rate 3.1415
Math. sqrt1_2 Square root of 1/2 0.707
Math. sqrt2 Square root of 2 1.414
Math. SQRT (X) Square root of X It depends on the value of X.
Math. Pow (x, n) Returns the nth power of X. The parameters are X and N.
Math. Log (N) Returns the natural logarithm of N. The parameter is N.
Math. exp (N) Returns the nth power of E. The parameter is N.

Trigonometric function

Math. Cos (X) Returns the cosine of X.
Math. Sin (X) Sine function of X
Math. Tan (X) Returns the tangent of X.
Math. ACOs (y) Returns the arc cosine of X.
Math. asin (y) Returns the arcsin of X.
Math. atan (y) Returns the arc tangent function of X.

Note: The unit of the return values of parameter X and inverse functions is radian (for example, PI radian = 180 degrees)

Rounding functions and random numbers

& Lt; TD width = "50%" & gt; math. Floor (x) & lt;/TD & gt; & Lt; TD width = "50%" & gt; math. Ceil (x) & lt;/TD & gt;
math. Random () Generate a random number from 0 to 1
math. Round (x) returns the value closest to integer x
take the value closest to integer x and smaller than x
take the value closest to integer x and greater than x
math. Min (a, B, c) return the smallest value in the parameter list
math. Max (a, B, c) return the maximum value in the parameter list

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.