Thursday, October 27, 2011

Syntax of Function pow(x, y)

This post just summarizes the syntax of power function pow(x,y) in C and C++.

ISO/ANSI C syntax:
double pow( double, double );

C++98 Functions:
float std::pow( float, float );
float std::pow( float, int );
double std::pow( double, double );
double std::pow( double, int );
long double std::pow( long double, long double );
long double std::pow( long double, int );

Under C++98 standard, the call std::pow(int, int) will be a compile error.
However, C++0X standard should be able to handle this. C++0X adds the additional overloads sufficient to ensure that:
  1. If any argument corresponding to a double parameter has type long double, then all arguments corresponding to double parameters are effectively casted to long double.
  2. Otherwise, if any argument corresponding to a double parameter has type double or an integer type, then all arguments corresponding to double parameters are effectively casted to double.
  3. Otherwise, all arguments corresponding to double parameters are effectively casted to float.


References:
http://www.daniweb.com/software-development/cpp/threads/108300

No comments:

Post a Comment