ridiculousfish / libdivide

Official git repository for libdivide: optimized integer division
http://libdivide.com
Other
1.1k stars 79 forks source link

#pragma warning( suppress : 4146 ) #16

Closed kimwalisch closed 8 years ago

kimwalisch commented 8 years ago

I saw your code:

        uint32_t absD = 1U << shift;
        if (more & LIBDIVIDE_NEGATIVE_DIVISOR) {
#if LIBDIVIDE_VC
#pragma warning( suppress : 4146 )
            absD = -absD;
#else
            absD = -absD;
#endif      
        }

I came across the same issue a few years ago and found a shorter solution (which I use here):

uint32_t absD = 1U << shift;
if (more & LIBDIVIDE_NEGATIVE_DIVISOR) {
    absD = absD * (uint32_t)-1;
}

I guess the compiler will generate the same code but you avoid the ugly pragma.

ridiculousfish commented 8 years ago

Nice tip! Thanks!!