Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. code pow(a,b) function in Visual studio 2010 professional

code pow(a,b) function in Visual studio 2010 professional

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studioregex
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrby123
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • M mrby123

      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

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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 a float, and the second one being a double. But there is no overload of the pow 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 use double.

      M 1 Reply Last reply
      0
      • J Jochen Arndt

        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 a float, and the second one being a double. But there is no overload of the pow 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 use double.

        M Offline
        M Offline
        mrby123
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • M mrby123

          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

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          Changing all float to double 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 use double because you are using the pow() function. If you add the return value to other values like in polynomial functions, there may be inexact results when using float.

          M 1 Reply Last reply
          0
          • J Jochen Arndt

            Changing all float to double 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 use double because you are using the pow() function. If you add the return value to other values like in polynomial functions, there may be inexact results when using float.

            M Offline
            M Offline
            mrby123
            wrote on last edited by
            #5

            thank you, really helped me.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups