]> www.ginac.de Git - cln.git/blob - tests/test_I_ilength.cc
Fix crashes in find_univpoly_ring and related functions
[cln.git] / tests / test_I_ilength.cc
1 #include "test_I.h"
2
3 int test_I_integer_length (int iterations)
4 {
5         int error = 0;
6         int i;
7         // Check against ash.
8         for (i = iterations; i > 0; i--) {
9                 cl_I a = testrandom_I();
10                 uintL l = integer_length(a);
11                 if (a >= 0) {
12                         int b = 0;
13                         if (a < ash(1,l)) {
14                                 if (a == 0)
15                                         b = (l == 0);
16                                 else
17                                         b = (l > 0 && a >= ash(1,l-1));
18                         }
19                         ASSERT1(b, a);
20                 } else {
21                         int b = 0;
22                         if (a >= ash(-1,l)) {
23                                 if (a == -1)
24                                         b = (l == 0);
25                                 else
26                                         b = (l > 0 && a < ash(-1,l-1));
27                         }
28                         ASSERT1(b, a);
29                 }
30         }
31         return error;
32 }