namespace math__private { template struct ZPowImpl { static double Calculate(double d) { return pow(d, t_numerator * 1.0 / t_denominator); } }; template struct ZPowImpl { static double Calculate(double d) { return d; } }; template<> struct ZPowImpl<1, 1> { static double Calculate(double d) { return d; } }; template<> struct ZPowImpl<1, 2> { static double Calculate(double d) { return sqrt(d); } }; template<> struct ZPowImpl<1, 3> { static double Calculate(double d) { return cbrt(d); } }; template struct ZPowImpl<0, t_denominator> { static double Calculate(double d) { return 1; } }; template struct ZPowImpl { static double Calculate(double d) { return ZPowImpl::Calculate(d) * d; } }; // absolute-value-power: have special implementations for even powers // TODO: do this for all even integer powers template struct ZPowAbsImpl; template struct ZPowAbsImpl { static double Calculate(double d) { return ZPowImpl::Calculate(fabs(d)); } }; template struct ZPowAbsImpl { static double Calculate(double d) { return ZPowImpl::Calculate(d); } }; };