brintos

brintos / llvm-project-archived public Read only

0
0
Text · 903 B · be263cc Raw
25 lines · c
1// RUN: %clang_cc1 -verify %s2 3// expected-no-diagnostics4 5/* WG14 N617: yes6 * reliable integer division7 */8void test(void) {9  _Static_assert(59 / 4 == 14, "we didn't truncate properly");10  _Static_assert(59 / -4 == -14, "we didn't truncate properly");11  _Static_assert(-59 / 4 == -14, "we didn't truncate properly");12  _Static_assert(-59 / -4 == 14, "we didn't truncate properly");13 14  // Might as well test % for the quotient.15  _Static_assert(59 % 4 == 3, "we didn't truncate properly");16  _Static_assert(59 % -4 == 3, "we didn't truncate properly");17  _Static_assert(-59 % 4 == -3, "we didn't truncate properly");18  _Static_assert(-59 % -4 == -3, "we didn't truncate properly");19 20  // Test the idiom for rounding up.21  _Static_assert((59 + (4 - 1)) / 4 == 15, "failed to 'round up' with the usual idiom");22  _Static_assert((59 + (4 - 1)) % 4 == 2, "failed to 'round up' with the usual idiom");23}24 25