How to do floor division with negative numbers ?

Revision en1, by maybesomeone, 2022-09-18 19:33:03

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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English maybesomeone 2022-09-18 19:33:03 252 Initial revision (published)