You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
882 B

25 years ago
  1. #include "test_I.h"
  2. int test_I_integer_length (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check against ash.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I a = testrandom_I();
  9. uintL l = integer_length(a);
  10. if (a >= 0) {
  11. #if !(defined(__GNUC__) && (__GNUC_MINOR__ < 8))
  12. ASSERT1(a < ash(1,l) && (a == 0 ? l == 0 : l > 0 && a >= ash(1,l-1)), a);
  13. #else // work around g++ 2.7.0 bug
  14. int b = 0;
  15. if (a < ash(1,l)) {
  16. if (a == 0)
  17. b = (l == 0);
  18. else
  19. b = (l > 0 && a >= ash(1,l-1));
  20. }
  21. ASSERT1(b, a);
  22. #endif
  23. } else {
  24. #if !(defined(__GNUC__) && (__GNUC_MINOR__ < 8))
  25. ASSERT1(a >= ash(-1,l) && (a == -1 ? l == 0 : l > 0 && a < ash(-1,l-1)), a);
  26. #else // work around g++ 2.7.0 bug
  27. int b = 0;
  28. if (a >= ash(-1,l)) {
  29. if (a == -1)
  30. b = (l == 0);
  31. else
  32. b = (l > 0 && a < ash(-1,l-1));
  33. }
  34. ASSERT1(b, a);
  35. #endif
  36. }
  37. }
  38. return error;
  39. }