code pow(a,b) function in Visual studio 2010 professional
-
1>c:\msw_give_out\void_effect_no_input_msw_shotplus_i_format\blast_vib_procdlg.cpp(1908): error C2666: 'pow' : 6 overloads have similar conversions 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(583): could be 'long double pow(long double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(581): or 'long double pow(long double,long double)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(535): or 'float pow(float,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(533): or 'float pow(float,float)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(497): or 'double pow(double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(122): or 'double pow(double,double)' 1> while trying to match the argument list '(float, double)' 1>c:\msw_give_out\void_effect_no_input_msw_shotplus_i_format\blast_vib_procdlg.cpp(1909): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>c:\msw_give_out\void_effect_no_input_msw_shotplus_i_format\blast_vib_procdlg.cpp(1923): error C2666: 'pow' : 6 overloads have similar conversions 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(583): could be 'long double pow(long double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(581): or 'long double pow(long double,long double)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(535): or 'float pow(float,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(533): or 'float pow(float,float)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(497): or 'double pow(double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(122): or 'double pow(double,double)' 1> while trying to match the argument list '(float, double)' How to fix the error? Thanks
-
1>c:\msw_give_out\void_effect_no_input_msw_shotplus_i_format\blast_vib_procdlg.cpp(1908): error C2666: 'pow' : 6 overloads have similar conversions 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(583): could be 'long double pow(long double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(581): or 'long double pow(long double,long double)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(535): or 'float pow(float,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(533): or 'float pow(float,float)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(497): or 'double pow(double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(122): or 'double pow(double,double)' 1> while trying to match the argument list '(float, double)' 1>c:\msw_give_out\void_effect_no_input_msw_shotplus_i_format\blast_vib_procdlg.cpp(1909): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>c:\msw_give_out\void_effect_no_input_msw_shotplus_i_format\blast_vib_procdlg.cpp(1923): error C2666: 'pow' : 6 overloads have similar conversions 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(583): could be 'long double pow(long double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(581): or 'long double pow(long double,long double)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(535): or 'float pow(float,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(533): or 'float pow(float,float)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(497): or 'double pow(double,int)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(122): or 'double pow(double,double)' 1> while trying to match the argument list '(float, double)' How to fix the error? Thanks
A good help would be if you have posted the line where the error occurs. However, the error states that you are calling the
pow
function with the first argument being afloat
, and the second one being adouble
. But there is no overload of thepow
function for these argument types. You should cast one value to the type of the other:float f1 = 2.0;
double f2 = 3.0;
// This will fail
//double f3 = pow(f1, f2);
// Use this instead
double f3 = pow(static_cast<double>(f1), f2);A general note: If you did not need the
float
type for a specific reason (usually memory), you should consider to always usedouble
. -
A good help would be if you have posted the line where the error occurs. However, the error states that you are calling the
pow
function with the first argument being afloat
, and the second one being adouble
. But there is no overload of thepow
function for these argument types. You should cast one value to the type of the other:float f1 = 2.0;
double f2 = 3.0;
// This will fail
//double f3 = pow(f1, f2);
// Use this instead
double f3 = pow(static_cast<double>(f1), f2);A general note: If you did not need the
float
type for a specific reason (usually memory), you should consider to always usedouble
. -
Thank you for your helpful correction. If I change all 'float' type to double, my program would be too large. How about change all types to 'float' ? Thanks
Changing all
float
todouble
in a program would not increase the size too much. Only the size of static and initialized floating point values is doubled. During runtime, the size of dynamically allocated values (arrays) is doubled. You may use float if you are sure that the precision is sufficient. This depends on the operations performed and the required accuracy. I added the note to better usedouble
because you are using thepow()
function. If you add the return value to other values like in polynomial functions, there may be inexact results when usingfloat
. -
Changing all
float
todouble
in a program would not increase the size too much. Only the size of static and initialized floating point values is doubled. During runtime, the size of dynamically allocated values (arrays) is doubled. You may use float if you are sure that the precision is sufficient. This depends on the operations performed and the required accuracy. I added the note to better usedouble
because you are using thepow()
function. If you add the return value to other values like in polynomial functions, there may be inexact results when usingfloat
.