ldexp() in C++
The ldexp() function takes two arguments a and b and returns the product of a and 2 raised to the power of b i.e., a * (2b).
Syntax:
double ldexp (double a, double b); float ldexp (float a, float b); long double ldexp (long double a, long double b);
- The ldexp() function takes two arguments a, b and computes a * (2b).
- Here a and b can be anything which is valid.
- The ldexp() function returns a * (2^b) if we pass a and b as the arguments.
Parameter:
Return:
- It is mandatory to give both the arguments otherwise it will give error no matching function for call to ‘ldexp()’.
- If we pass string as argument we will get error no matching function for call to ‘ldexp(const char [n], const char [n]) .
- If we pass std::numeric_limits::max() as both the arguments we will get inf(infinity) as output.
Errors and exceptions associated with this function:
Examples:
Input : ldexp(5.35, 4) Output : 85.6
Input : ldexp(25, 5) Output : 800
# CODE 1
// CPP implemenatation of the // above function #include <cmath> #include <iostream> using namespace std; int main() { double a = 5.35; int b = 4; cout << ldexp(a, b); return 0; } |
chevron_right
filter_none
Output:
85.6
# CODE 2
// CPP implementation of the // above function #include <cmath> #include <iostream> using namespace std; int main() { int a = 25, b = 5; cout << ldexp(a, b); return 0; } |
chevron_right
filter_none
Output:
800
Recommended Posts:
- ldexp() function in C/C++
- Difference between Inheritance and Polymorphism
- Difference between Single and Multiple Inheritance in C++
- Difference between Abstraction and Encapsulation in C++
- return statement in C/C++ with Examples
- How to implement our own Vector Class in C++?
- Web Programming in C++
- C++ Program to print an Array using Recursion
- Storage Classes in C++ with Examples
- fill_n() function in C++ STL with examples
- fill() function in C++ STL with examples
- How to erase an element from a vector using erase() and reverse_iterator?
- iomanip setbase() function in C++ with Examples
- iomanip setpricision() function in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



