4 ms·
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
by garaetjjte 4y ago
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 https://godbolt.org/z/qrraj8s6j