Running test-all-metal-shared results in the following failure for utilities.c:
metal: error: -10 divided by 3 rounded down is -3 instead of -4 and rounded up is -2 instead of -3
The relevant code in lib/utilities.h is:
/** Divide (and round down). */
#define metal_div_round_down(num, den) \
((num) / (den))
/** Divide (and round up). */
#define metal_div_round_up(num, den) \
metal_div_round_down((num) + (den) - 1, (den))
This is wrong for negative results because C integer division truncates toward zero, so for negative results, it rounds up.
Running test-all-metal-shared results in the following failure for utilities.c:
metal: error: -10 divided by 3 rounded down is -3 instead of -4 and rounded up is -2 instead of -3
The relevant code in lib/utilities.h is:
This is wrong for negative results because C integer division truncates toward zero, so for negative results, it rounds up.