Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-01-27 22:55:49


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk