Jump to content
  • Advertisement
Sign in to follow this  

error C2666: 'pow' : 7 overloads

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay i have the OpenGL book from glbook.gamedev.net terrain.cpp(255): error C2666: 'pow' : 7 overloads have similar conversions float dh = (float)rectSize/2,r = (double)pow(2,-1*rough); appearently it works fine in vc6. but not in vc7, i dont know why.

Share this post


Link to post
Share on other sites
Advertisement
a.) One declaration per line.
b.) static_cast<float>(rectSize)/2.0;
c.) std::pow(2.0, 1.0*static_cast<float>(rough));

From 'man pow':

double
pow(double x, double y);

long double
powl(long double x, long double y);

float
powf(float x, float y);

Share this post


Link to post
Share on other sites
Flangazor: man pow will give you the C definitions, the C++ pow function is overloaded to respond to the types you give it.

Thanhda: If you're making a float, why cast pow to double? and as Flangazor says, one declaration per line

If you want pow to return a float, then pass your arguments as floats. If you're concerned that pow(float, float) is less accurate than pow(double, double), don't be, it is at least as accurate as its return type.

Constructors will implicitly type-cast, there's no need to tell the compiler what type to make the results of those expressions (remember than in a declaration, int foo = bar; is equivalent to int foo(bar);).

float dh = rectSize/2.0f;
float r = pow(2.0f, -1.0f*rough);

Should handle all the types correctly

Share this post


Link to post
Share on other sites
nice thanks works.

float dh = (float)rectSize/2;
float r = (double)pow( (double)2,(double)(-1*rough));

works as well. but pretty much same code. thanks a lot.

Share this post


Link to post
Share on other sites
That isn't 'pretty much the same code'. Symphonic's is readable and yours isn't. You should use 2.0f and -1.0f for the constants instead of casting to doubles (or even floats).

Sorry for forgetting the f's on the constants. And I realise man pow will give C declarations. I don't remember why I posted it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!