maint: update all copyright year number ranges
[gnulib.git] / tests / test-ffsl.c
index 2da2f5c..410b128 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Free Software Foundation, Inc.
+ * Copyright (C) 2011-2013 Free Software Foundation, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,11 +26,13 @@ SIGNATURE_CHECK (ffsl, int, (long int));
 
 #include "macros.h"
 
+#define NBITS (sizeof (long int) * CHAR_BIT)
+
 static int
 naive (long int i)
 {
   unsigned long int j;
-  for (j = 0; j < CHAR_BIT * sizeof i; j++)
+  for (j = 0; j < NBITS; j++)
     if (i & (1UL << j))
       return j + 1;
   return 0;
@@ -39,14 +41,28 @@ naive (long int i)
 int
 main (int argc, char *argv[])
 {
-  long int i;
+  long int x;
+  int i;
 
   for (i = -128; i <= 128; i++)
     ASSERT (ffsl (i) == naive (i));
-  for (i = 0; i < CHAR_BIT * sizeof i; i++)
+  for (i = 0; i < NBITS; i++)
     {
       ASSERT (ffsl (1UL << i) == naive (1UL << i));
       ASSERT (ffsl (1UL << i) == i + 1);
+      ASSERT (ffsl (-1UL << i) == i + 1);
+    }
+  for (i = 0; i < NBITS - 1; i++)
+    {
+      ASSERT (ffsl (3UL << i) == i + 1);
+      ASSERT (ffsl (-3UL << i) == i + 1);
+    }
+  for (i = 0; i < NBITS - 2; i++)
+    {
+      ASSERT (ffsl (5UL << i) == i + 1);
+      ASSERT (ffsl (-5UL << i) == i + 1);
+      ASSERT (ffsl (7UL << i) == i + 1);
+      ASSERT (ffsl (-7UL << i) == i + 1);
     }
   return 0;
 }