Problem with pow function

This is not compiling for me for some reason.
I have at the beginning of the program #include<cmath>
It is giving me an error saying there is something wrong with the pow function.

1
2
3
4
5
6
	float n;
	for(float i = 0.0; i < total_countries; i++)
		if(pow(2,i) < total_countries)
			n = i;
	float increment = pow(2,n);
	cout << increment;
What exactly does it say?

PS: Using floats in for functions is kinda meh.
Last edited on
Unrelated note:

With integers, 1 << x is the same as, but much faster than (and less lossy) than pow(2,x);

Therefore the above could be optimized to this:

1
2
3
4
5
6
int n;
for(int i = 0; i < total_countries; i++)
    if((1<<i) < total_countries)
        n = i;
int increment = 1 << n;
cout << increment;
Disch great thinking with using bitwise operators, sometimes you have all the information in front of you but you don't look at the little things! So thanks for opening my eyes!
Topic archived. No new replies allowed.