Sign in to follow this  
OpenGL_Guru

Another .NET compiler issue concering the pow(..) function

Recommended Posts

sorry for another thread on VC6 to VC.NET but here is the code in question that the compiler in complaing about.. i am using this to assign alpha values to the alpha bit..
  if(_isnan(cdf->values[index]))
   glColor4f(1, 1, 1, 0); 
  else
   glColor4f(1, 1, 1, (pow(2, (1-getColor(cdf->values[index]))) -1) /1);


getColor will come back as a float and 1 - that is a float. here is the error that i get... c:\Documents and Settings\VC_NET\Vc7\PlatformSDK\MyProjects\Katrina\kat.CPP(183): error C2666: 'pow' : 7 overloads have similar conversions i looked up C2666 on MSDN but the only thing that i can tell is somehow is doesnt like the 2 raised to the float power. the weird thing is is that VC 6 NEVER complained about this... any thoughts??

Share this post


Link to post
Share on other sites
Quote:
Original post by TheDarkening
Try 2.0f and (1.0f - getColor(cdf->values[index]))


that did work Darkening... well that really is baffling.. why did this happen or why was the compiler complaining? it wasnt treating it as a warning but rather an error. Also really strange that VC 6 never gave me a problem with that.

i would really like to know deeper of why this error showed its ugly head.. anyway thanks again..

Share this post


Link to post
Share on other sites
there are 7 overloads for pow(a, b)

float pow( float, float );
int pow( int, int );
double pow( double, double );
...

well (1 - getFloat()) is returning a float value but i strongly suggest 1.0f so if the compiler doesnt optimize it for you then there is no casting.


pow(2, getFloat())
2 is an int, getFloat() is a float
doesnt know which to use.

pow(2.0, getFloat())
2.0 is a double, getFloat() is a float
doesnt know which to use but i would have figured that it would cast the float into a double, guess not.

pow(2.0f, getFloat())
both are float.
all good.


you should always do 1.0f for your floats, for making a game doubles are rarely required. GetFloat() * 2.0 or 2.0 * GetFloat() may return a double, with 2.0f it will be a float.

Does that help?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That and .net is usually stricter in the type converting. At least on my machine anyway, have to specify between float and double most of the time. But this is a good thing though, helps spot errors better and its safer.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheDarkening
there are 7 overloads for pow(a, b)

float pow( float, float );
int pow( int, int );
double pow( double, double );
...

Actually, there are only 6 overloads in the standard libraries for pow that I see in the standard, and int pow( int, int ) isn't one of them. In addition to those, there are also 7 different pow function templates (for valarray and complex). I'm not sure why .NET is reporting 7 overloads unless it provides an extra one as a nonstandard extension. Does anyone have a list of the pow overloads that .NET uses or can they point out where another overload is in the standard which I may be missing?

The proper standard overloads that I know of are

double pow( double, double )
double pow( double, int )

float pow( float, float )
float pow( float, int )

long double pow( long double, long double )
long double pow( long double, int )

Share this post


Link to post
Share on other sites
These are the ones .NET has:

double pow(double,double)
double pow(double,int)
double pow(int,int)
float pow(float,float)
float pow(float,int)
long double pow(long double,long double)
long double pow(long double,int)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this