global immutable integer Arrays are now completely functional!

This makes the following code work:
uint echo (uint val)
{
    return val;
}

const(uint) fastLog10(const uint val) pure nothrow @nogc {
    return      (val < 10) ? 0 :
                (val < 100) ? 1 :
                (val < 1000) ? 2 :
                (val < 10000) ? 3 :
                (val < 100000) ? 4 :
                (val < 1000000) ? 5 :
                (val < 10000000) ? 6 :
                (val < 100000000) ? 7 :
                (val < 1000000000) ? 8 : 9;
}

/*@unique*/ static immutable uint[10] fastPow10tbl = [
        1,
        10,
        100,
        1000,
        10000,
        100000,
        1000000,
        10000000,
        100000000,
        1000000000,
] ;

static assert(fastLog10(fastPow10tbl[2]) == 2);
static assert(fastLog10(fastPow10tbl[3]) == 3);
static assert(fastLog10(1000) == 3);

static assert(echo(fastPow10tbl[1]) == 10);

Reply via email to