How to use ldexp() function to multiplies a floating point by the number 2 raised to the exp power in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double x = 0.97;
	int exp = 5;
	double result = ldexp(x, exp);

	cout << x << " * 2^" << exp << " = " << result << endl;

	return 0;
}

/*
run:

0.97 * 2^5 = 31.04

*/

 



answered Mar 22, 2016 by avibootz
...