Why does std :: pow float and int cause this overload?

Following:

#include <cmath>

int main()
{
    float base = 2.0f;
    float result = std::pow(base, 2);
    return 0;
}

Raises warning a -Wconversionif it is enabled. Wandbox

It seems that doubleoverload is being called std::powwhere I expect overload to be selected float(with an exponent intother than float). Can someone who knows its overload explain why?

+4
source share
2 answers

++ 11, pow - , double. double, , long double, long double.

[c.math]

++ float long double overloaded .

, , :

  • , , long double, , , long double.

  • , , , double integer, , , double.

  • , , float.

, :

  • long doublelong double
  • floatfloat
  • double
+4

cpp reference

7) , 1-3). - , . , Promoted double, .

" - , " , double float.

float       pow( float base, float exp );
0

Source: https://habr.com/ru/post/1672948/


All Articles