Sign in to follow this  

error C2666 VC++ 05, help!

This topic is 3843 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

Heres my error: ///// error C2666: 'fmod' : 3 overloads have similar conversions c:\program files\microsoft visual studio 8\vc\include\math.h(561): could be 'long double fmod(long double,long double)' c:\program files\microsoft visual studio 8\vc\include\math.h(513): or 'float fmod(float,float)' c:\program files\microsoft visual studio 8\vc\include\math.h(120): or 'double fmod(double,double)'while trying to match the argument list '(float, double)' ///// How can I fix this?

Share this post


Link to post
Share on other sites
Since you didn't post any code, I can't be sure, but here's what I think is happening:

You are calling the fmod function like so:
fmod(1.0, 0.0);

In which case, the compiler can interpret those numbers as floats, doubles, or long doubles, so it doesn't know what to do. You can make it explicit by either putting in casts, or, for the float version, appending the letter 'f' to each of the numbers:
//call fmod(double, double)
fmod(static_cast<double>(1.0), static_cast<double>(0.0));

//call fmod(float, float)
fmod(1.f, 0.f);

Share this post


Link to post
Share on other sites
Coerce the arguments to the appropriate function call in to the same type.

e.g.

fmod(static_cast<double>(x), static_cast<double>(y));



Put yourself in the compiler's shoes. If you were asked to compile fmod(x, y) where x is a float and y is a double, which overload would you choose?

Share this post


Link to post
Share on other sites
Quote:
Original post by Driv3MeFar
You are calling the fmod function like so:
fmod(1.0, 0.0);

In which case, the compiler can interpret those numbers as floats, doubles, or long doubles, so it doesn't know what to do.

Those are both doubles, so that should compile just fine. What is more likely is that one of the parameters is a variable of type float and the other paramter is a constant without F appended to it. For example,
fmod(x,0.5);

where x is a variable of type float. For some reason people tend to use floats when using variables, but doubles when using immediates.

Share this post


Link to post
Share on other sites

This topic is 3843 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.

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