1 /* Test of integer_length_ll().
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 #include "integer_length.h"
25 #define NBITS (sizeof (unsigned long long) * CHAR_BIT)
28 naive (unsigned long long x
)
31 for (j
= NBITS
- 1; j
>= 0; j
--)
38 main (int argc
, char *argv
[])
43 for (x
= 0; x
<= 256; x
++)
44 ASSERT (integer_length_ll (x
) == naive (x
));
45 for (i
= 0; i
< NBITS
; i
++)
47 ASSERT (integer_length_ll (1ULL << i
) == naive (1ULL << i
));
48 ASSERT (integer_length_ll (1ULL << i
) == i
+ 1);
49 ASSERT (integer_length_ll (-1ULL << i
) == NBITS
);
51 for (i
= 0; i
< NBITS
- 1; i
++)
52 ASSERT (integer_length_ll (3ULL << i
) == i
+ 2);
53 for (i
= 0; i
< NBITS
- 2; i
++)
54 ASSERT (integer_length_ll (-3ULL << i
) == NBITS
);
55 for (i
= 0; i
< NBITS
- 2; i
++)
57 ASSERT (integer_length_ll (5ULL << i
) == i
+ 3);
58 ASSERT (integer_length_ll (7ULL << i
) == i
+ 3);
60 for (i
= 0; i
< NBITS
- 3; i
++)
62 ASSERT (integer_length_ll (-5ULL << i
) == NBITS
);
63 ASSERT (integer_length_ll (-7ULL << i
) == NBITS
);