maybesomeone's blog

By maybesomeone, history, 2 years ago, In English

like we do ceil division like this

int64_t ceil_div(int64_t a, int64_t b) {
    return a / b + ((a ^ b) > 0 && a % b != 0);
}

how to do floor division with negative numbers also.

  • Vote: I like it
  • +3
  • Vote: I do not like it