C++ Math log2()30 Aug 2024 | 2 min read The function computes the base 2 logarithm of a given number. Suppose a number is 'x':SyntaxNote: The return_type can be float, double or long double.Parameterx: The value whose logarithm is to be calculated. Return value
Example 1Let's see the simple example when the value of x is greater than one. Output: Value of x is : 2 log2(x) = 1 In this example, log2() function computes the logarithm value of base 2 when the value of x is greater than one Example 2Let's see the simple example when the value of x is equal to 1. Output: Value of x is : 1 log2(x) = 0 In this example, log2() function computes the logarithm value of base 2 when the value of x is equal to one. Example 3Let's see the simple example when the value of x lies between 0 and 1. Output: Value of x is : 0.2 log2(x) = -2.32193 In this example, log2() function computes the logarithm value of base 2 when the value of x is equal to 0.2. Example 4Let's see the simple example when the value of x is equal to zero. Output: Value of x is : 0 log2(x) = -inf In this example, log2() function computes the logarithm value of base 2 when the value of x is equal to 0. Example 5Let's see the simple example when the value of x is less than zero. Output: Value of x is : -1.5 log2(x) = nan In this example, log2() function computes the logarithm value of base 2 when the value of x is less than zero. Next TopicC++ Math Functions |
math erf() function
C++ Math erf() The erf() function computes the error function value of a parameter passed to the function. Syntax Suppose a number is 'x': float erf( float x); double erf( double x); long double erf( long double x); double erf( integral x); Parameter x: It is a floating point value. Return value It returns the error function...
2 min read
math asin() function
C++ Math asin() The function computes the inverse sine of a number given in radian. asin(x) = sin-1x Syntax Suppose a number is 'x'. Syntax would be: float asin(float x); double asin(double x); long double asin(long double x); double asin(integral x); Note: If the value passed is an integer type, then it is cast to...
2 min read
math rint() function
C++ Math rint() The function rounds off the given value to the nearest integer using current rounding mode. The current rounding mode is determined by fesetround(). For example: rint(7.9) = 8; if, fesetround(FE_DOWNWARD) then, rint(7.9) = 7; Syntax Suppose a number 'x'. Syntax would be: return_type rint(data_type x); Note: The return_type can be float, double...
1 min read
math cbrt() function
C++ Math cbrt() This function is used to find the cube root of a given number. Consider a argument 'arg' : Cube root of a number : ∛arg Syntax Syntax would be : double cbrt(double arg); float cbrt(float arg); long double cbrt(long double arg); double cbrt(integral arg); Parameter arg : It is the value of float or...
1 min read
math tan() function
C++ Math tan() Function In the C++ programming language, the finds the tangent of an angle specified in terms of radians. It is part of the <cmath> header file. It can take arguments of type float, double, or long double, and return a value equivalent...
6 min read
math exp2() function
C++ Math exp2() The function computes the base - 2 exponential function of a given number. Suppose a number is 'x': exp2(x) = 2<sup>x</sup> Syntax float exp2(float x); double exp2(double x); long double exp2(long double x); double exp2(integral x); Parameter x: It is the value of the exponent. Return value It returns, 2 raised to the power x....
1 min read
math atan2() function
C++ Math atan2() The function finds the inverse tangent of a coordinate. Suppose the coordinate is (x,y): atan2(y,x) = tan-1(y/x); Syntax Suppose the coordinate is (x,y). Syntax would be: float atan2(float y, float x); double atan2(double y, double x); long double atan2(long double y, long double x); Promoted atan2(Arithmetic1 y, Arithmetic x ); Parameter y: It represents...
2 min read
math scalbln() function
C++ Math scalbln() The function computes the product of a given number and FLT_RADX raised to the power of exponent. Suppose a number is 'x' and exponent is 'n': scalbn(x,n) = x * ( FLT_RADX)n Syntax float scalbln(float x, long int n); double scalbln(double x, long int n); long double scalbln(long double x,...
1 min read
math abs() function
C++ Math abs() The function finds the absolute value of a given number. Suppose a number is 'x': abs(x) = |x|; Difference between abs() and fabs() The abs() function does not support float or double type arguments while fabs() function supports float, double as well as integer type arguments. Syntax int abs( int...
1 min read
math islessgreater() function
C++ Math islessgreater() The islessgreater() fuinction determines whether the value of first argument is less than or greater than the value of second argument. If the value of first argument is less than or greater than the second argument then it returns 1 otherwise 0. Note: If one...
2 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India