News for hackers. Stuff that matters.
Re:Figuring out round, floor and ceil with integer division by garaetjjte on Saturday November 26, 2022 @06:14AM (#33751737)
In case divisor is always positive, you can use these variants:

    int divF(int a, int b) { return a / b - (a % b < 0); }
    int divC(int a, int b) { return a / b + (a % b > 0); }
They should be faster as it avoids branching: https://godbolt.org/z/qrraj8s6j

There are no comments on this comment yet.