 Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER # Math methods in JS

In JavaScript, we have math methods that can be used without actually creating them. It allows us to perform mathematical tasks on numbers.

`Example: Math.LN2It returns the natural logarithm of 2.`

Some of the math properties(constants) are:

` Math.E        // returns Euler's number Math.PI       // returns PI Math.SQRT2    // returns the square root of 2 Math.SQRT1_2  // returns the square root of 1/2 Math.LN2      // returns the natural logarithm of 2 Math.LN10     // returns the natural logarithm of 10 Math.LOG2E    // returns base 2 logarithm of E Math.LOG10E   // returns base 10 logarithm of E `

Some of the Math methods are:

`abs(x)        // Returns the absolute value of xcbrt(x)       // Returns the cubic root of xceil(x)       // Returns x, rounded upwards to the nearest integerclz32(x)      // Returns the number of leading zeros in a 32-bit binary representation of xexp(x)        // Returns the value of Exexpm1(x)      // Returns the value of Ex minus 1floor(x)      // Returns x, rounded downwards to the nearest integerfround(x)     // Returns the nearest (32-bit single precision) float representation of a numberlog(x)        // Returns the natural logarithmof xlog10(x)      // Returns the base-10 logarithm of xlog1p(x)      // Returns the natural logarithm of 1 + xlog2(x)       // Returns the base-2 logarithm of xpow(x, y)     // Returns the value of x to the power of yrandom()      // Returns a random number between 0 and 1round(x)      // Rounds x to the nearest integersign(x)       // Returns the sign of a number (checks whether it is positive, negative or zero)sqrt(x)       // Returns the square root of xtrunc(x)      // Returns the integer part of a number (x)max(x, y, z, ..., n)  // Returns the number with the highest valuemin(x, y, z, ..., n)  // Returns the number with the lowest value`

Example: Suppose we want to find the max among 1,7 and 77, then Math.max(1,7,77) will give us the required results.

Some of the Trigonometric methods are:

`acos(x)       // Returns the arccosine of x, in radiansacosh(x)      // Returns the hyperbolic arccosine of xasin(x)       // Returns the arcsine of x, in radiansasinh(x)      // Returns the hyperbolic arcsine of xatan(x)       // Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radiansatan2(y, x)   // Returns the arctangent of the quotient of its argumentsatanh(x)      // Returns the hyperbolic arctangent of xcos(x)        // Returns the cosine of x (x is in radians)cosh(x)       // Returns the hyperbolic cosine of xsin(x)        // Returns the sine of x (x is in radians)sinh(x)       // Returns the hyperbolic sine of xtan(x)        // Returns the tangent of an angletanh(x)       // Returns the hyperbolic tangent of a number`

Try the following example in the editor below.

You are given an integer N, you have to print the nearest integral value for the base-2 logarithm of N.

Sample Input:

101

Sample Output:

7 Hints
• Hints are not available for this problem

## Discussion Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer 