
28 Jan
2005
28 Jan
'05
3:55 a.m.
Would the following work in all cases? My assumption is that if an oscillation is going to occur, the two numbers will always be off by exactly one. template < unsigned int N, unsigned int X = 1, unsigned int X2 = ( X + N / X ) / 2, unsigned int XP1 = X + 1 > struct Sqrt { enum ValueStorage { Value = typename Sqrt < N, X2 > :: Value }; }; template < unsigned int N, unsigned int X, unsigned int XP1 > struct Sqrt < N, X, X, XP1 > { enum ValueStorage { Value = X }; }; template < unsigned int N, unsigned int X, unsigned int XP1 > struct Sqrt < N, X, XP1, XP1 > { enum ValueStorage { Value = X }; }; -Jason