xref: /llvm-project/clang/test/C/C99/n617.c (revision d7e06d5675b62b5d3d89e6d6210c34b74a1a8356)
1 // RUN: %clang_cc1 -verify %s
2 
3 // expected-no-diagnostics
4 
5 /* WG14 N617: yes
6  * reliable integer division
7  */
test(void)8 void 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