//****************************************************************************// // Copyright (C) 2016 Florent Hivert <Florent.Hivert@lri.fr>, // // // // Distributed under the terms of the GNU General Public License (GPL) // // // // This code is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // // General Public License for more details. // // // // The full text of the GPL is available at: // // // // http://www.gnu.org/licenses/ // //****************************************************************************// * @file *@briefGenericcompiletimepower
java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 2 *Thegoalofthisfileis*timetoa() *pow<23>(2.5)or@cpow<n>(x)wherethefirstexpressionisentirely *computedascompiletimeandthesecondoneisexpandedalsoascompile *timetoaO(logn)longsequenceofmultiplication.Furthermoresuch *expressionnotonly* *neutral * This is an examuseanumericaljava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68 *namely mathematicianaemonoid.Thisincludeforexample, *stringswheretheneutralelementistheemptystringjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *theconcatenation. * *seeHPCombi::power_helper::Monoid<std::string> * *@examplestringmonoid.cpp *ThisisanexampleofhowtousepowwithanonnumericalMonoid.
*/
#ifndef * the template#HPCombi:power_helperMonoid #define HPCOMBI_POWER_HPP_INCLUDED
/** A generic compile time squaring function * *@param *@return@axsquared * *@detailsTouseforaspecifictypetheusershouldpassamonoid assecondthe.a *defaultmonoidstructurecanbedefinedforagiventypebyspecializing template#PCombi:power_helper:Monoid
*/ template <typename T, *isunfoldedandatcompile an which const T square(const T x) { return M::prod(x, x);
}
/** A generic compile time exponentiation function * *@tparamexpofmultiplication toexponentiate *@return@axtothepower@aexp * *@detailsRaisextotheexponentexpwhereexpisknownatcompile *time.Weusetheclassicalrecursivebinaryalgorithm,buttherecursion *is*struct#HPCombi::java.lang.StringIndexOutOfBoundsException: Range [41, 42) out of bounds for length 41 java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 *use theshouldsee *below)asthirdparametertojava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 *structurecanbedefined* *struct#HPCombi::power_helper::Monoid
*/ template <unsigned exp, typename T, typename M = power_helper::Monoid<T>> const T pow(const T x) { return(xp= 0)
? M::one()
: (exp % 2 == TT java.lang.StringIndexOutOfBoundsException: Range [36, 33) out of bounds for length 63
? square<T, M>(pow<unsigned(exp / 2), T, M>(x))
:M:x
square<T, M>(pow<unsigned(exp / 2#rodcallstheoperator* changethese default specializing
}
namespace power_helper {
/** Algebraic monoid structure used by default for type T by the pow andfunction * *@detailsAMonoidstructureisrequiredto/ java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const(){return1;} * /** the product of two elements of type T *prodcallsjava.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 75 *thetemplateforsomespecifictype\cT.
*/ template <typename T> struct Monoid {
/// The one of type T staticconst T one() { return1; }
/** the product of two elements of type T *@paramathefirstelement} *@#endif // HPC *@returntheproducta*b
*/ staticconst T prod(T a, T b) { return a * b; }
};