Better to crash with an assertion than to get into an infinite loop.
We cold work around this, but there's a bug here and it's not a
rounding bug, so it's better not to conceal it.
double percentage = child->percent > 0.0 ? child->percent : 1.0 / children;
assigned += sizes[i++] = percentage * total;
}
+ assert(assigned == total ||
+ (assigned > total && assigned - total <= children * 2) ||
+ (assigned < total && total - assigned <= children * 2));
int signal = assigned < total ? 1 : -1;
while (assigned != total) {
- for (i = 0; i < children && assigned < total; ++i) {
+ for (i = 0; i < children && assigned != total; ++i) {
sizes[i] += signal;
assigned += signal;
}