ldexp() function in C/C++ Last Updated : 21 Aug, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The ldexp() is a built-in function in C/C++ gives the product of any variable x and 2 raised to the power of exp by taking two arguments x and exp i.e., x * 2^exp Syntax: float ldexp (float x, int exp) double ldexp (double x, int exp) long double ldexp (long double x, int exp) double ldexp (T x, int exp) Parameter: The function accepts two mandatory parameter x and exp which specifies the two variables described in the definition. Return Value: The function returns the value of the expression x * 2^exp. It returns a value of type long double, float or double. Below programs illustrates the above function. Program 1: CPP // C++ program to illustrate the // ldexp() function #include <bits/stdc++.h> using namespace std; int main() { double x = 6, result; int exp = 2; // It returns x*(2^exp) result = ldexp(x, exp); // print the result cout << "ldexp(x, exp) = " << result << endl; return 0; } Output: ldexp(x, exp) = 24 Program 2: CPP // C++ program to illustrate the // ldexp() function #include <bits/stdc++.h> using namespace std; int main() { double result; int x = 20, exp = 9; // It returns x*(2^exp) result = ldexp(x, exp); // prints the result cout << "ldexp(x, exp) = " << result << endl; return 0; } Output: ldexp(x, exp) = 10240 Errors and Exceptions: If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL (or HUGE_VALF or HUGE_VALL) with the proper sign, and an overflow range error occurs. Below programs illustrates the above error. CPP // C++ program to illustrate the // ldexp() function #include <bits/stdc++.h> using namespace std; int main() { double result; int x = 20, exp = 10000; // It returns x*(2^exp) result = ldexp(x, exp); // prints the result cout << "ldexp(x, exp) = " << result << endl; return 0; } Output: ldexp(x, exp) = inf Comment More infoAdvertise with us Next Article ldexp() function in C/C++ A AmanSrivastava1 Follow Improve Article Tags : Misc C++ CPP-Functions C-Library Practice Tags : CPPMisc Similar Reads std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read log() Function in C++ The std::log() in C++ is a built-in function that is used to calculate the natural logarithm (base e) of a given number. The number can be of any data type i.e. int, double, float, long long. It is defined inside the <cmath> header file.In this article we will learn about how to use std::log() 1 min read strtod() function in C/C++ The strtod() is a builtin function in C and C++ STL which interprets the contents of the string as a floating point number and return its value as a double. It sets a pointer to point to the first character after the last valid character of the string, only if there is any, otherwise it sets the poi 4 min read strol() function in C++ The strtol() function in C++ interprets the contents of a string as an integral number of the specified base and return its value as a long int.This function also sets an end pointer that points to the first character after the last valid numeric character of the string, if there is no such characte 3 min read lldiv() function in C++ STL The lldiv() is a builtin function in C++ STL which gives us the quotient and remainder of the division of two numbers. Syntax: lldiv(n, d) Parameters: The function accepts two mandatory parameters which are described below: n: It specifies the dividend. The data-type can be long long or long long in 2 min read Like