Exemple #1
0
int main( void )
{
    TESTCASE( imaxabs( (intmax_t)0 ) == 0 );
    TESTCASE( imaxabs( INTMAX_MAX ) == INTMAX_MAX );
    TESTCASE( imaxabs( INTMAX_MIN + 1 ) == -( INTMAX_MIN + 1 ) );
    return TEST_RESULTS;
}
Exemple #2
0
void runSuccess() {
    imaxabs(INTMAX_C(1));
    imaxabs(INTMAX_C(0));
    imaxabs(INTMAX_C(-1));
    imaxabs(INTMAX_MAX);
    imaxabs(getnonminimax());
}
Exemple #3
0
static char * test_imaxabs(void)
{
    pu_assert("", imaxabs((intmax_t)0) == 0);
    pu_assert("", imaxabs(INTMAX_MAX) == INTMAX_MAX);
    pu_assert("", imaxabs(INTMAX_MIN + 1) == -(INTMAX_MIN + 1));

    return NULL;
}
Exemple #4
0
int
main (void)
{
    {
        intmax_t result = imaxabs (0);
        ASSERT (result == 0);
    }
    {
        intmax_t result = imaxabs (23);
        ASSERT (result == 23);
    }
    {
        intmax_t result = imaxabs (-23);
        ASSERT (result == 23);
    }

    return 0;
}
Exemple #5
0
void testValues() {
    f = 2;
    intmax_t result;
    
    result = imaxabs(INTMAX_C(1));
    //@ assert result == 1;
    result = imaxabs(INTMAX_C(0));
    //@ assert result == 0;
    result = imaxabs(INTMAX_C(-1));
    //@ assert result == 1;
    result = imaxabs(INTMAX_MAX);
    //@ assert result == INTMAX_MAX;
    result = imaxabs(getnonminimax());
    //@ assert result >= 0;
    
    //@ assert f == 2;
    //@ assert vacuous: \false;
}
void
tst_unsigned (unsigned *pu, unsigned long *pl, unsigned long long *pll,
	      uintmax_t *pm)
{
  *pu = abs (*pu);      /* { dg-warning "taking the absolute value of unsigned type" } */
  *pl = labs (*pl);     /* { dg-warning "taking the absolute value of unsigned type" } */
  *pll = llabs (*pll);  /* { dg-warning "taking the absolute value of unsigned type" } */
  *pm = imaxabs (*pm);      /* { dg-warning "taking the absolute value of unsigned type" } */
}
int main()
{
    {
    int8_t  i1 = 0;
    int16_t i2 = 0;
    int32_t i3 = 0;
    int64_t i4 = 0;
    }
    {
    uint8_t  i1 = 0;
    uint16_t i2 = 0;
    uint32_t i3 = 0;
    uint64_t i4 = 0;
    }
    {
    int_least8_t  i1 = 0;
    int_least16_t i2 = 0;
    int_least32_t i3 = 0;
    int_least64_t i4 = 0;
    }
    {
    uint_least8_t  i1 = 0;
    uint_least16_t i2 = 0;
    uint_least32_t i3 = 0;
    uint_least64_t i4 = 0;
    }
    {
    int_fast8_t  i1 = 0;
    int_fast16_t i2 = 0;
    int_fast32_t i3 = 0;
    int_fast64_t i4 = 0;
    }
    {
    uint_fast8_t  i1 = 0;
    uint_fast16_t i2 = 0;
    uint_fast32_t i3 = 0;
    uint_fast64_t i4 = 0;
    }
    {
    intptr_t  i1 = 0;
    uintptr_t i2 = 0;
    intmax_t  i3 = 0;
    uintmax_t i4 = 0;
    }
    {
    imaxdiv_t  i1 = {0};
    }
    intmax_t i = 0;
    static_assert((std::is_same<decltype(imaxabs(i)), intmax_t>::value), "");
    static_assert((std::is_same<decltype(imaxdiv(i, i)), imaxdiv_t>::value), "");
    static_assert((std::is_same<decltype(strtoimax("", (char**)0, 0)), intmax_t>::value), "");
    static_assert((std::is_same<decltype(strtoumax("", (char**)0, 0)), uintmax_t>::value), "");
    static_assert((std::is_same<decltype(wcstoimax(L"", (wchar_t**)0, 0)), intmax_t>::value), "");
    static_assert((std::is_same<decltype(wcstoumax(L"", (wchar_t**)0, 0)), uintmax_t>::value), "");
}
int main()
{
    test<int8_t >();
    test<int16_t>();
    test<int32_t>();
    test<int64_t>();

    test<uint8_t >();
    test<uint16_t>();
    test<uint32_t>();
    test<uint64_t>();

    test<int_least8_t >();
    test<int_least16_t>();
    test<int_least32_t>();
    test<int_least64_t>();

    test<uint_least8_t >();
    test<uint_least16_t>();
    test<uint_least32_t>();
    test<uint_least64_t>();

    test<int_fast8_t >();
    test<int_fast16_t>();
    test<int_fast32_t>();
    test<int_fast64_t>();

    test<uint_fast8_t >();
    test<uint_fast16_t>();
    test<uint_fast32_t>();
    test<uint_fast64_t>();

    test<intptr_t >();
    test<uintptr_t>();
    test<intmax_t >();
    test<uintmax_t>();

    {
    imaxdiv_t  i1 = {};
    ((void)i1); // Prevent unused warning
    }

    intmax_t i = 0;
    ((void)i); // Prevent unused warning
    static_assert((std::is_same<decltype(imaxabs(i)), intmax_t>::value), "");
    static_assert((std::is_same<decltype(imaxdiv(i, i)), imaxdiv_t>::value), "");
    static_assert((std::is_same<decltype(strtoimax("", (char**)0, 0)), intmax_t>::value), "");
    static_assert((std::is_same<decltype(strtoumax("", (char**)0, 0)), uintmax_t>::value), "");
    static_assert((std::is_same<decltype(wcstoimax(L"", (wchar_t**)0, 0)), intmax_t>::value), "");
    static_assert((std::is_same<decltype(wcstoumax(L"", (wchar_t**)0, 0)), uintmax_t>::value), "");
}
Exemple #9
0
ATF_TC_BODY(imaxabs_basic, tc)
{
	static const struct {
		intmax_t val;
		intmax_t res;
	} table[] = {
		{ 0,		0		},
		{ INT_MAX,	INT_MAX		},
		{ -INT_MAX,	INT_MAX		},
		{ LONG_MAX,	LONG_MAX	},
		{ -LONG_MAX,	LONG_MAX	},
		{ LLONG_MAX,	LLONG_MAX	},
		{ -LLONG_MAX,	LLONG_MAX	},
		{ INT_MAX,	INT_MAX		},
		{ -INT_MAX,	INT_MAX		},
	};

	for (size_t i = 0; i < __arraycount(table); i++)
		ATF_CHECK(imaxabs(table[i].val) == table[i].res);
}
    p = SCNdFAST8;
    p = SCNi8;
    p = SCNiLEAST8;
    p = SCNiFAST8;
    p = SCNo8;
    p = SCNoLEAST8;
    p = SCNoFAST8;
    p = SCNu8;
    p = SCNuLEAST8;
    p = SCNuFAST8;
    p = SCNx8;
    p = SCNxLEAST8;
    p = SCNxFAST8;
#endif
    TEST_TRACE(C99 7.8.2.1)
    TEST(imaxabs((intmax_t)-10) == 10, "imaxabs of -10 is 10");
    TEST(imaxabs((intmax_t)10) == 10, "imaxabs of 10 is 10");
    TEST_TRACE(C99 7.8.2.2)
    maxdiv = imaxdiv((intmax_t)123, (intmax_t)10);
    TEST(maxdiv.quot == 12, "123 / 10 = 12");
    TEST(maxdiv.rem == 3, "123 %% 10 = 3");
    TEST_TRACE(C99 7.8.2.3)
    intmax_t m;
    m = strtoimax("100", 0, 0);
    TEST_EXCLUDE(MICROBLAZE, "http://ellcc.org/bugzilla/show_bug.cgi?id=54")
        TEST(m == 100, "strtoimax(\"100\", 0, 0) == 100 (%" PRIdMAX ")", m);
        TEST_FAIL(MICROBLAZE, m == 100, "strtoimax(\"100\", 0, 0) == 100 (%" PRIdMAX ")", m);
    uintmax_t um;
    um = strtoumax("100", 0, 0);
    TEST(um == 100, "strtoumax(\"100\", 0, 0) == 100");
#define BIGNUM "100000000000000000000000000000000000000"
Exemple #11
0
void runFailure() {
    imaxabs(INTMAX_MIN);
}
Exemple #12
0
static int BasicTest(
  size_t n,
  const int bound_on_0,
  const int bound_on_1,
  const int bound_on_2,
  const int bound_on_3,
  const char *lattice_name,
  const UINT8 total_ref_0,
  const UINT8 total_ref_1,
  const UINT8 total_ref_2,
  const UINT8 total_ref_3
  )
{

  const int bound_on[4] = {bound_on_0, bound_on_1, bound_on_2, bound_on_3};
  const UINT8 total_ref[4] = {total_ref_0, total_ref_1, total_ref_2, total_ref_3};

  // Create lattice tiling
  LatticeTiling *tiling = XLALCreateLatticeTiling(n);
  XLAL_CHECK(tiling != NULL, XLAL_EFUNC);

  // Add bounds
  for (size_t i = 0; i < n; ++i) {
    XLAL_CHECK(bound_on[i] == 0 || bound_on[i] == 1, XLAL_EFAILED);
    XLAL_CHECK(XLALSetLatticeTilingConstantBound(tiling, i, 0.0, bound_on[i] * pow(100.0, 1.0/n)) == XLAL_SUCCESS, XLAL_EFUNC);
  }

  // Set metric to the Lehmer matrix
  const double max_mismatch = 0.3;
  {
    gsl_matrix *GAMAT(metric, n, n);
    for (size_t i = 0; i < n; ++i) {
      for (size_t j = 0; j < n; ++j) {
        const double ii = i+1, jj = j+1;
        gsl_matrix_set(metric, i, j, jj >= ii ? ii/jj : jj/ii);
      }
    }
    XLAL_CHECK(XLALSetTilingLatticeAndMetric(tiling, lattice_name, metric, max_mismatch) == XLAL_SUCCESS, XLAL_EFUNC);
    GFMAT(metric);
    printf("Number of (tiled) dimensions: %zu (%zu)\n", XLALTotalLatticeTilingDimensions(tiling), XLALTiledLatticeTilingDimensions(tiling));
    printf("  Bounds: %i %i %i %i\n", bound_on_0, bound_on_1, bound_on_2, bound_on_3);
    printf("  Lattice type: %s\n", lattice_name);
  }

  // Create lattice tiling locator
  LatticeTilingLocator *loc = XLALCreateLatticeTilingLocator(tiling);
  XLAL_CHECK(loc != NULL, XLAL_EFUNC);
  if (lalDebugLevel & LALINFOBIT) {
    printf("  Index trie:\n");
    XLAL_CHECK(XLALPrintLatticeTilingIndexTrie(loc, stdout) == XLAL_SUCCESS, XLAL_EFUNC);
  }

  for (size_t i = 0; i < n; ++i) {

    // Create lattice tiling iterator and locator over 'i+1' dimensions
    LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator(tiling, i+1);
    XLAL_CHECK(itr != NULL, XLAL_EFUNC);

    // Count number of points
    const UINT8 total = XLALTotalLatticeTilingPoints(itr);
    printf("Number of lattice points in %zu dimensions: %" LAL_UINT8_FORMAT "\n", i+1, total);
    XLAL_CHECK(imaxabs(total - total_ref[i]) <= 1, XLAL_EFUNC,
               "ERROR: |total - total_ref[%zu]| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > 1", i, total, total_ref[i]);
    for (UINT8 k = 0; XLALNextLatticeTilingPoint(itr, NULL) > 0; ++k) {
      const UINT8 itr_index = XLALCurrentLatticeTilingIndex(itr);
      XLAL_CHECK(k == itr_index, XLAL_EFUNC,
                 "ERROR: k = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT " = itr_index", k, itr_index);
    }
    XLAL_CHECK(XLALResetLatticeTilingIterator(itr) == XLAL_SUCCESS, XLAL_EFUNC);

    // Check tiling statistics
    printf("  Check tiling statistics ...");
    for (size_t j = 0; j < n; ++j) {
      const LatticeTilingStats *stats = XLALLatticeTilingStatistics(tiling, j);
      XLAL_CHECK(stats != NULL, XLAL_EFUNC);
      XLAL_CHECK(imaxabs(stats->total_points - total_ref[j]) <= 1, XLAL_EFAILED, "\n  "
                 "ERROR: |total - total_ref[%zu]| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > 1", j, stats->total_points, total_ref[j]);
      XLAL_CHECK(stats->min_points <= stats->avg_points, XLAL_EFAILED, "\n  "
                 "ERROR: min_points = %" LAL_INT4_FORMAT " > %g = avg_points", stats->min_points, stats->avg_points);
      XLAL_CHECK(stats->max_points >= stats->avg_points, XLAL_EFAILED, "\n  "
                 "ERROR: max_points = %" LAL_INT4_FORMAT " < %g = avg_points", stats->max_points, stats->avg_points);
    }
    printf(" done\n");

    // Get all points
    gsl_matrix *GAMAT(points, n, total);
    XLAL_CHECK(XLALNextLatticeTilingPoints(itr, &points) == (int)total, XLAL_EFUNC);
    XLAL_CHECK(XLALNextLatticeTilingPoint(itr, NULL) == 0, XLAL_EFUNC);

    // Get nearest points to each template, check for consistency
    printf("  Testing XLALNearestLatticeTiling{Point|Block}() ...");
    gsl_vector *GAVEC(nearest, n);
    UINT8Vector *nearest_indexes = XLALCreateUINT8Vector(n);
    XLAL_CHECK(nearest_indexes != NULL, XLAL_ENOMEM);
    for (UINT8 k = 0; k < total; ++k) {
      gsl_vector_const_view point_view = gsl_matrix_const_column(points, k);
      const gsl_vector *point = &point_view.vector;
      XLAL_CHECK(XLALNearestLatticeTilingPoint(loc, point, nearest, nearest_indexes) == XLAL_SUCCESS, XLAL_EFUNC);
      gsl_vector_sub(nearest, point);
      double err = gsl_blas_dasum(nearest) / n;
      XLAL_CHECK(err < 1e-6, XLAL_EFAILED, "\n  "
                 "ERROR: err = %e < 1e-6", err);
      XLAL_CHECK(nearest_indexes->data[i] == k, XLAL_EFAILED, "\n  "
                 "ERROR: nearest_indexes[%zu] = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT "\n", i, nearest_indexes->data[i], k);
      if (0 < i) {
        const LatticeTilingStats *stats = XLALLatticeTilingStatistics(tiling, i);
        UINT8 nearest_index = 0;
        UINT4 nearest_left = 0, nearest_right = 0;
        XLAL_CHECK(XLALNearestLatticeTilingBlock(loc, point, i, nearest, &nearest_index, &nearest_left, &nearest_right) == XLAL_SUCCESS, XLAL_EFUNC);
        XLAL_CHECK(nearest_index == nearest_indexes->data[i-1], XLAL_EFAILED, "\n  "
                   "ERROR: nearest_index = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT "\n", nearest_index, nearest_indexes->data[i-1]);
        UINT4 nearest_len = 1 + nearest_left + nearest_right;
        XLAL_CHECK(nearest_len <= stats->max_points, XLAL_EFAILED, "\n  "
                   "ERROR: nearest_len = %i > %i = stats[%zu]->max_points\n", nearest_len, stats->max_points, i);
      }
      if (i+1 < n) {
        const LatticeTilingStats *stats = XLALLatticeTilingStatistics(tiling, i+1);
        UINT8 nearest_index = 0;
        UINT4 nearest_left = 0, nearest_right = 0;
        XLAL_CHECK(XLALNearestLatticeTilingBlock(loc, point, i+1, nearest, &nearest_index, &nearest_left, &nearest_right) == XLAL_SUCCESS, XLAL_EFUNC);
        XLAL_CHECK(nearest_index == nearest_indexes->data[i], XLAL_EFAILED, "\n  "
                   "ERROR: nearest_index = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT "\n", nearest_index, nearest_indexes->data[i]);
        UINT4 nearest_len = 1 + nearest_left + nearest_right;
        XLAL_CHECK(nearest_len <= stats->max_points, XLAL_EFAILED, "\n  "
                   "ERROR: nearest_len = %i > %i = stats[%zu]->max_points\n", nearest_len, stats->max_points, i+1);
      }
    }
    printf(" done\n");

    // Cleanup
    XLALDestroyLatticeTilingIterator(itr);
    GFMAT(points);
    GFVEC(nearest);
    XLALDestroyUINT8Vector(nearest_indexes);

  }

  for (size_t i = 0; i < n; ++i) {

    // Create alternating lattice tiling iterator over 'i+1' dimensions
    LatticeTilingIterator *itr_alt = XLALCreateLatticeTilingIterator(tiling, i+1);
    XLAL_CHECK(itr_alt != NULL, XLAL_EFUNC);
    XLAL_CHECK(XLALSetLatticeTilingAlternatingIterator(itr_alt, true) == XLAL_SUCCESS, XLAL_EFUNC);

    // Count number of points, check for consistency with non-alternating count
    UINT8 total = 0;
    while (XLALNextLatticeTilingPoint(itr_alt, NULL) > 0) ++total;
    XLAL_CHECK(imaxabs(total - total_ref[i]) <= 1, XLAL_EFUNC, "ERROR: alternating |total - total_ref[%zu]| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > 1", i, total, total_ref[i]);

    // Cleanup
    XLALDestroyLatticeTilingIterator(itr_alt);

  }

  // Cleanup
  XLALDestroyLatticeTiling(tiling);
  XLALDestroyLatticeTilingLocator(loc);
  LALCheckMemoryLeaks();
  printf("\n");
  fflush(stdout);

  return XLAL_SUCCESS;

}
Exemple #13
0
static int MismatchTest(
  LatticeTiling *tiling,
  gsl_matrix *metric,
  const double max_mismatch,
  const UINT8 total_ref,
  const double mism_hist_ref[MISM_HIST_BINS]
  )
{

  const size_t n = XLALTotalLatticeTilingDimensions(tiling);

  // Create lattice tiling iterator and locator
  LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator(tiling, n);
  XLAL_CHECK(itr != NULL, XLAL_EFUNC);
  LatticeTilingLocator *loc = XLALCreateLatticeTilingLocator(tiling);
  XLAL_CHECK(loc != NULL, XLAL_EFUNC);

  // Count number of points
  const UINT8 total = XLALTotalLatticeTilingPoints(itr);
  printf("Number of lattice points: %" LAL_UINT8_FORMAT "\n", total);
  XLAL_CHECK(imaxabs(total - total_ref) <= 1, XLAL_EFUNC, "ERROR: |total - total_ref| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > 1", total, total_ref);

  // Get all points
  gsl_matrix *GAMAT(points, n, total);
  XLAL_CHECK(XLALNextLatticeTilingPoints(itr, &points) == (int)total, XLAL_EFUNC);
  XLAL_CHECK(XLALNextLatticeTilingPoint(itr, NULL) == 0, XLAL_EFUNC);

  // Initialise mismatch histogram counts
  double mism_hist[MISM_HIST_BINS] = {0};
  double mism_hist_total = 0, mism_hist_out_of_range = 0;

  // Perform 10 injections for every template
  {
    gsl_matrix *GAMAT(injections, 3, total);
    gsl_matrix *GAMAT(nearest, 3, total);
    gsl_matrix *GAMAT(temp, 3, total);
    RandomParams *rng = XLALCreateRandomParams(total);
    XLAL_CHECK(rng != NULL, XLAL_EFUNC);
    for (size_t i = 0; i < 10; ++i) {

      // Generate random injection points
      XLAL_CHECK(XLALRandomLatticeTilingPoints(tiling, 0.0, rng, injections) == XLAL_SUCCESS, XLAL_EFUNC);

      // Find nearest lattice template points
      XLAL_CHECK(XLALNearestLatticeTilingPoints(loc, injections, &nearest, NULL) == XLAL_SUCCESS, XLAL_EFUNC);

      // Compute mismatch between injections
      gsl_matrix_sub(nearest, injections);
      gsl_blas_dsymm(CblasLeft, CblasUpper, 1.0, metric, nearest, 0.0, temp);
      for (size_t j = 0; j < temp->size2; ++j) {
        gsl_vector_view temp_j = gsl_matrix_column(temp, j);
        gsl_vector_view nearest_j = gsl_matrix_column(nearest, j);
        double mismatch = 0.0;
        gsl_blas_ddot(&nearest_j.vector, &temp_j.vector, &mismatch);
        mismatch /= max_mismatch;

        // Increment mismatch histogram counts
        ++mism_hist_total;
        if (mismatch < 0.0 || mismatch > 1.0) {
          ++mism_hist_out_of_range;
        } else {
          ++mism_hist[lround(floor(mismatch * MISM_HIST_BINS))];
        }

      }

    }

    // Cleanup
    GFMAT(injections, nearest, temp);
    XLALDestroyRandomParams(rng);

  }

  // Normalise histogram
  for (size_t i = 0; i < MISM_HIST_BINS; ++i) {
    mism_hist[i] *= MISM_HIST_BINS / mism_hist_total;
  }

  // Print mismatch histogram and its reference
  printf("Mismatch histogram: ");
  for (size_t i = 0; i < MISM_HIST_BINS; ++i) {
    printf(" %0.3f", mism_hist[i]);
  }
  printf("\n");
  printf("Reference histogram:");
  for (size_t i = 0; i < MISM_HIST_BINS; ++i) {
    printf(" %0.3f", mism_hist_ref[i]);
  }
  printf("\n");

  // Determine error between mismatch histogram and its reference
  double mism_hist_error = 0.0;
  for (size_t i = 0; i < MISM_HIST_BINS; ++i) {
    mism_hist_error += fabs(mism_hist[i] - mism_hist_ref[i]);
  }
  mism_hist_error /= MISM_HIST_BINS;
  printf("Mismatch histogram error: %0.3e\n", mism_hist_error);
  const double mism_hist_error_tol = 5e-2;
  if (mism_hist_error >= mism_hist_error_tol) {
    XLAL_ERROR(XLAL_EFAILED, "ERROR: mismatch histogram error exceeds %0.3e\n", mism_hist_error_tol);
  }

  // Check fraction of injections out of histogram range
  const double mism_out_of_range = mism_hist_out_of_range / mism_hist_total;
  printf("Fraction of points out of histogram range: %0.3e\n", mism_out_of_range);
  const double mism_out_of_range_tol = 2e-3;
  if (mism_out_of_range > mism_out_of_range_tol) {
    XLAL_ERROR(XLAL_EFAILED, "ERROR: fraction of points out of histogram range exceeds %0.3e\n", mism_out_of_range_tol);
  }

  // Perform 10 injections outside parameter space
  {
    gsl_matrix *GAMAT(injections, 3, 10);
    gsl_matrix *GAMAT(nearest, n, total);
    RandomParams *rng = XLALCreateRandomParams(total);
    XLAL_CHECK(rng != NULL, XLAL_EFUNC);

    // Generate random injection points outside parameter space
    XLAL_CHECK(XLALRandomLatticeTilingPoints(tiling, 5.0, rng, injections) == XLAL_SUCCESS, XLAL_EFUNC);

    // Find nearest lattice template points
    XLAL_CHECK(XLALNearestLatticeTilingPoints(loc, injections, &nearest, NULL) == XLAL_SUCCESS, XLAL_EFUNC);

    // Cleanup
    GFMAT(injections, nearest);
    XLALDestroyRandomParams(rng);

  }

  // Cleanup
  XLALDestroyLatticeTiling(tiling);
  XLALDestroyLatticeTilingIterator(itr);
  XLALDestroyLatticeTilingLocator(loc);
  GFMAT(metric, points);
  LALCheckMemoryLeaks();
  printf("\n");
  fflush(stdout);

  return XLAL_SUCCESS;

}
Exemple #14
0
void
main_test (void)
{
  /* For each type, test both runtime and compile time (constant folding)
     optimization.  */
  volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX;
  volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX;
  volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL;
  volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__;
  volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1;
  volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX;
  if (abs (i0) != 0)
    abort ();
  if (abs (0) != 0)
    link_error ();
  if (abs (i1) != 1)
    abort ();
  if (abs (1) != 1)
    link_error ();
  if (abs (im1) != 1)
    abort ();
  if (abs (-1) != 1)
    link_error ();
  if (abs (imin) != INT_MAX)
    abort ();
  if (abs (-INT_MAX) != INT_MAX)
    link_error ();
  if (abs (imax) != INT_MAX)
    abort ();
  if (abs (INT_MAX) != INT_MAX)
    link_error ();
  if (labs (l0) != 0L)
    abort ();
  if (labs (0L) != 0L)
    link_error ();
  if (labs (l1) != 1L)
    abort ();
  if (labs (1L) != 1L)
    link_error ();
  if (labs (lm1) != 1L)
    abort ();
  if (labs (-1L) != 1L)
    link_error ();
  if (labs (lmin) != LONG_MAX)
    abort ();
  if (labs (-LONG_MAX) != LONG_MAX)
    link_error ();
  if (labs (lmax) != LONG_MAX)
    abort ();
  if (labs (LONG_MAX) != LONG_MAX)
    link_error ();
  if (llabs (ll0) != 0LL)
    abort ();
  if (llabs (0LL) != 0LL)
    link_error ();
  if (llabs (ll1) != 1LL)
    abort ();
  if (llabs (1LL) != 1LL)
    link_error ();
  if (llabs (llm1) != 1LL)
    abort ();
  if (llabs (-1LL) != 1LL)
    link_error ();
  if (llabs (llmin) != __LONG_LONG_MAX__)
    abort ();
  if (llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
    link_error ();
  if (llabs (llmax) != __LONG_LONG_MAX__)
    abort ();
  if (llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
    link_error ();
  if (imaxabs (imax0) != 0)
    abort ();
  if (imaxabs (0) != 0)
    link_error ();
  if (imaxabs (imax1) != 1)
    abort ();
  if (imaxabs (1) != 1)
    link_error ();
  if (imaxabs (imaxm1) != 1)
    abort ();
  if (imaxabs (-1) != 1)
    link_error ();
  if (imaxabs (imaxmin) != INTMAX_MAX)
    abort ();
  if (imaxabs (-INTMAX_MAX) != INTMAX_MAX)
    link_error ();
  if (imaxabs (imaxmax) != INTMAX_MAX)
    abort ();
  if (imaxabs (INTMAX_MAX) != INTMAX_MAX)
    link_error ();
}
Exemple #15
0
int
main()	{
	int	status = 0;		/* exit status to be returned */

    OPENTEST();
	
	/* <stdint.h> features: */

	fprintf(outfile,"CHAR_BIT=%u\n", (unsigned)CHAR_BIT );
	fprintf(outfile,"sizeof(char)=%u\n", (unsigned)sizeof(char));	/* s.b. 1 */
	fprintf(outfile,"sizeof(short)=%u\n", (unsigned)sizeof(short));
	fprintf(outfile,"sizeof(int)=%u\n", (unsigned)sizeof(int));
	fprintf(outfile,"sizeof(long)=%u\n", (unsigned)sizeof(long));
#ifdef	__Q8_QT
	fprintf(outfile,"sizeof(long long)=%u\n", (unsigned)sizeof(__Q8_QT));
#else
	fprintf(outfile,"*** long long isn't defined ***\n");
#endif
	fprintf(outfile,"sizeof(intmax_t)=%u\n", (unsigned)sizeof(intmax_t));
	fprintf(outfile,"sizeof(ptrdiff_t)=%u\n", (unsigned)sizeof(ptrdiff_t));
	fprintf(outfile,"sizeof(size_t)=%u\n", (unsigned)sizeof(size_t));
	fprintf(outfile,"sizeof(sig_atomic_t)=%u\n", (unsigned)sizeof(sig_atomic_t));
	fprintf(outfile,"sizeof(wchar_t)=%u\n", (unsigned)sizeof(wchar_t));
#if	defined(WINT_MAX) || __STDC_VERSION__ >= 199901
	fprintf(outfile,"sizeof(wint_t)=%u\n", (unsigned)sizeof(wint_t));
#else
	fprintf(outfile,"*** wint_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INT8_MAX
	fprintf(outfile,"sizeof(int8_t)=%u\n", (unsigned)sizeof(int8_t));
	fprintf(outfile,"sizeof(uint8_t)=%u\n", (unsigned)sizeof(uint8_t));
#endif
#ifdef	INT9_MAX
	fprintf(outfile,"sizeof(int9_t)=%u\n", (unsigned)sizeof(int9_t));
	fprintf(outfile,"sizeof(uint9_t)=%u\n", (unsigned)sizeof(uint9_t));
#endif
#ifdef	INT12_MAX
	fprintf(outfile,"sizeof(int12_t)=%u\n", (unsigned)sizeof(int12_t));
	fprintf(outfile,"sizeof(uint12_t)=%u\n", (unsigned)sizeof(uint12_t));
#endif
#ifdef	INT16_MAX
	fprintf(outfile,"sizeof(int16_t)=%u\n", (unsigned)sizeof(int16_t));
	fprintf(outfile,"sizeof(uint16_t)=%u\n", (unsigned)sizeof(uint16_t));
#endif
#ifdef	INT18_MAX
	fprintf(outfile,"sizeof(int18_t)=%u\n", (unsigned)sizeof(int18_t));
	fprintf(outfile,"sizeof(uint18_t)=%u\n", (unsigned)sizeof(uint18_t));
#endif
#ifdef	INT24_MAX
	fprintf(outfile,"sizeof(int24_t)=%u\n", (unsigned)sizeof(int24_t));
	fprintf(outfile,"sizeof(uint24_t)=%u\n", (unsigned)sizeof(uint24_t));
#endif
#ifdef	INT32_MAX
	fprintf(outfile,"sizeof(int32_t)=%u\n", (unsigned)sizeof(int32_t));
	fprintf(outfile,"sizeof(uint32_t)=%u\n", (unsigned)sizeof(uint32_t));
#endif
#ifdef	INT36_MAX
	fprintf(outfile,"sizeof(int36_t)=%u\n", (unsigned)sizeof(int36_t));
	fprintf(outfile,"sizeof(uint36_t)=%u\n", (unsigned)sizeof(uint36_t));
#endif
#ifdef	INT40_MAX
	fprintf(outfile,"sizeof(int40_t)=%u\n", (unsigned)sizeof(int40_t));
	fprintf(outfile,"sizeof(uint40_t)=%u\n", (unsigned)sizeof(uint40_t));
#endif
#ifdef	INT48_MAX
	fprintf(outfile,"sizeof(int48_t)=%u\n", (unsigned)sizeof(int48_t));
	fprintf(outfile,"sizeof(uint48_t)=%u\n", (unsigned)sizeof(uint48_t));
#endif
#ifdef	INT60_MAX
	fprintf(outfile,"sizeof(int60_t)=%u\n", (unsigned)sizeof(int60_t));
	fprintf(outfile,"sizeof(uint60_t)=%u\n", (unsigned)sizeof(uint60_t));
#endif
#ifdef	INT64_MAX
	fprintf(outfile,"sizeof(int64_t)=%u\n", (unsigned)sizeof(int64_t));
	fprintf(outfile,"sizeof(uint64_t)=%u\n", (unsigned)sizeof(uint64_t));
#endif
#ifdef	INT72_MAX
	fprintf(outfile,"sizeof(int72_t)=%u\n", (unsigned)sizeof(int72_t));
	fprintf(outfile,"sizeof(uint72_t)=%u\n", (unsigned)sizeof(uint72_t));
#endif
#ifdef	INT128_MAX
	fprintf(outfile,"sizeof(int128_t)=%u\n", (unsigned)sizeof(int128_t));
	fprintf(outfile,"sizeof(uint128_t)=%u\n", (unsigned)sizeof(uint128_t));
#endif
	fprintf(outfile,"sizeof(int_least8_t)=%u\n", (unsigned)sizeof(int_least8_t));
	fprintf(outfile,"sizeof(uint_least8_t)=%u\n", (unsigned)sizeof(uint_least8_t));
	fprintf(outfile,"sizeof(int_least16_t)=%u\n", (unsigned)sizeof(int_least16_t));
	fprintf(outfile,"sizeof(uint_least16_t)=%u\n", (unsigned)sizeof(uint_least16_t));
	fprintf(outfile,"sizeof(int_least32_t)=%u\n", (unsigned)sizeof(int_least32_t));
	fprintf(outfile,"sizeof(uint_least32_t)=%u\n", (unsigned)sizeof(uint_least32_t));
#ifdef	INT_LEAST64_MAX
	fprintf(outfile,"sizeof(int_least64_t)=%u\n", (unsigned)sizeof(int_least64_t));
	fprintf(outfile,"sizeof(uint_least64_t)=%u\n", (unsigned)sizeof(uint_least64_t));
#else
	fprintf(outfile,"*** uint_least64_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INT_LEAST128_MAX
	fprintf(outfile,"sizeof(int_least128_t)=%u\n", (unsigned)sizeof(int_least128_t));
	fprintf(outfile,"sizeof(uint_least128_t)=%u\n",
		(unsigned)sizeof(uint_least128_t));
#endif
	fprintf(outfile,"sizeof(int_fast8_t)=%u\n", (unsigned)sizeof(int_fast8_t));
	fprintf(outfile,"sizeof(uint_fast8_t)=%u\n", (unsigned)sizeof(uint_fast8_t));
	fprintf(outfile,"sizeof(int_fast16_t)=%u\n", (unsigned)sizeof(int_fast16_t));
	fprintf(outfile,"sizeof(uint_fast16_t)=%u\n", (unsigned)sizeof(uint_fast16_t));
	fprintf(outfile,"sizeof(int_fast32_t)=%u\n", (unsigned)sizeof(int_fast32_t));
	fprintf(outfile,"sizeof(uint_fast32_t)=%u\n", (unsigned)sizeof(uint_fast32_t));
#ifdef	INT_FAST64_MAX
	fprintf(outfile,"sizeof(int_fast64_t)=%u\n", (unsigned)sizeof(int_fast64_t));
	fprintf(outfile,"sizeof(uint_fast64_t)=%u\n", (unsigned)sizeof(uint_fast64_t));
#else
	fprintf(outfile,"*** int_fast64_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INT_FAST128_MAX
	fprintf(outfile,"sizeof(int_fast128_t)=%u\n", (unsigned)sizeof(int_fast128_t));
	fprintf(outfile,"sizeof(uint_fast128_t)=%u\n", (unsigned)sizeof(uint_fast128_t));
#endif
#if	defined(INTPTR_MAX)
	fprintf(outfile,"sizeof(intptr_t)=%u\n", (unsigned)sizeof(intptr_t));
#if	defined(UINTPTR_MAX)
	fprintf(outfile,"sizeof(uintptr_t)=%u\n", (unsigned)sizeof(uintptr_t));
#else
	fprintf(outfile,"*** intptr_t is defined but uintptr_t isn't ***\n");
	status = EXIT_FAILURE;
#endif
#elif	defined(UINTPTR_MAX)
	fprintf(outfile,"sizeof(uintptr_t)=%u\n", (unsigned)sizeof(uintptr_t));
	fprintf(outfile,"*** uintptr_t is defined but intptr_t isn't ***\n");
	status = EXIT_FAILURE;
#else
	fprintf(outfile,"*** neither intptr_t nor uintptr_t is defined ***\n");
	status = EXIT_FAILURE;
#endif
#ifdef	INTMAX_MAX
	fprintf(outfile,"sizeof(intmax_t)=%u\n", (unsigned)sizeof(intmax_t));
	fprintf(outfile,"sizeof(uintmax_t)=%u\n", (unsigned)sizeof(uintmax_t));
#else
	fprintf(outfile,"*** intmax_t isn't defined ***\n");
	status = EXIT_FAILURE;
#endif

#ifdef	INT8_MAX
	fprintf(outfile,"INT8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT8_MIN);
	fprintf(outfile,"INT8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT8_MAX);
	fprintf(outfile,"UINT8_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT8_MAX);
#endif
#ifdef	INT9_MAX
	fprintf(outfile,"INT9_MIN=%"PRIdMAX"\n", (__Q8_MT)INT9_MIN);
	fprintf(outfile,"INT9_MAX=%"PRIdMAX"\n", (__Q8_MT)INT9_MAX);
	fprintf(outfile,"UINT9_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT9_MAX);
#endif
#ifdef	INT12_MAX
	fprintf(outfile,"INT12_MIN=%"PRIdMAX"\n", (__Q8_MT)INT12_MIN);
	fprintf(outfile,"INT12_MAX=%"PRIdMAX"\n", (__Q8_MT)INT12_MAX);
	fprintf(outfile,"UINT12_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT12_MAX);
#endif
#ifdef	INT16_MAX
	fprintf(outfile,"INT16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT16_MIN);
	fprintf(outfile,"INT16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT16_MAX);
	fprintf(outfile,"UINT16_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT16_MAX);
#endif
#ifdef	INT18_MAX
	fprintf(outfile,"INT18_MIN=%"PRIdMAX"\n", (__Q8_MT)INT18_MIN);
	fprintf(outfile,"INT18_MAX=%"PRIdMAX"\n", (__Q8_MT)INT18_MAX);
	fprintf(outfile,"UINT18_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT18_MAX);
#endif
#ifdef	INT24_MAX
	fprintf(outfile,"INT24_MIN=%"PRIdMAX"\n", (__Q8_MT)INT24_MIN);
	fprintf(outfile,"INT24_MAX=%"PRIdMAX"\n", (__Q8_MT)INT24_MAX);
	fprintf(outfile,"UINT24_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT24_MAX);
#endif
#ifdef	INT32_MAX
	fprintf(outfile,"INT32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT32_MIN);
	fprintf(outfile,"INT32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT32_MAX);
	fprintf(outfile,"UINT32_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT32_MAX);
#endif
#ifdef	INT36_MAX
	fprintf(outfile,"INT36_MIN=%"PRIdMAX"\n", (__Q8_MT)INT36_MIN);
	fprintf(outfile,"INT36_MAX=%"PRIdMAX"\n", (__Q8_MT)INT36_MAX);
	fprintf(outfile,"UINT36_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT36_MAX);
#endif
#ifdef	INT40_MAX
	fprintf(outfile,"INT40_MIN=%"PRIdMAX"\n", (__Q8_MT)INT40_MIN);
	fprintf(outfile,"INT40_MAX=%"PRIdMAX"\n", (__Q8_MT)INT40_MAX);
	fprintf(outfile,"UINT40_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT40_MAX);
#endif
#ifdef	INT48_MAX
	fprintf(outfile,"INT48_MIN=%"PRIdMAX"\n", (__Q8_MT)INT48_MIN);
	fprintf(outfile,"INT48_MAX=%"PRIdMAX"\n", (__Q8_MT)INT48_MAX);
	fprintf(outfile,"UINT48_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT48_MAX);
#endif
#ifdef	INT60_MAX
	fprintf(outfile,"INT60_MIN=%"PRIdMAX"\n", (__Q8_MT)INT60_MIN);
	fprintf(outfile,"INT60_MAX=%"PRIdMAX"\n", (__Q8_MT)INT60_MAX);
	fprintf(outfile,"UINT60_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT60_MAX);
#endif
#ifdef	INT64_MAX
	fprintf(outfile,"INT64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT64_MIN);
	fprintf(outfile,"INT64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT64_MAX);
	fprintf(outfile,"UINT64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT64_MAX);
#endif
#ifdef	INT72_MAX
	fprintf(outfile,"INT72_MIN=%"PRIdMAX"\n", (__Q8_MT)INT72_MIN);
	fprintf(outfile,"INT72_MAX=%"PRIdMAX"\n", (__Q8_MT)INT72_MAX);
	fprintf(outfile,"UINT72_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT72_MAX);
#endif
#ifdef	INT128_MAX
	fprintf(outfile,"INT128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT128_MIN);
	fprintf(outfile,"INT128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT128_MAX);
	fprintf(outfile,"UINT128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT128_MAX);
#endif
	fprintf(outfile,"INT_LEAST8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST8_MIN);
	fprintf(outfile,"INT_LEAST8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST8_MAX);
	fprintf(outfile,"UINT_LEAST8_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_LEAST8_MAX);
	fprintf(outfile,"INT_LEAST16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST16_MIN);
	fprintf(outfile,"INT_LEAST16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST16_MAX);
	fprintf(outfile,"UINT_LEAST16_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_LEAST16_MAX);
	fprintf(outfile,"INT_LEAST32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST32_MIN);
	fprintf(outfile,"INT_LEAST32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST32_MAX);
	fprintf(outfile,"UINT_LEAST32_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_LEAST32_MAX);
#ifdef	INT_LEAST64_MAX
	fprintf(outfile,"INT_LEAST64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST64_MIN);
	fprintf(outfile,"INT_LEAST64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST64_MAX);
	fprintf(outfile,"UINT_LEAST64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_LEAST64_MAX);
#endif
#ifdef	INT_LEAST128_MAX
	fprintf(outfile,"INT_LEAST128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST128_MIN);
	fprintf(outfile,"INT_LEAST128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST128_MAX);
	fprintf(outfile,"UINT_LEAST128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_LEAST128_MAX);
#endif
	fprintf(outfile,"INT_FAST8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST8_MIN);
	fprintf(outfile,"INT_FAST8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST8_MAX);
	fprintf(outfile,"UINT_FAST8_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_FAST8_MAX);
	fprintf(outfile,"INT_FAST16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST16_MIN);
	fprintf(outfile,"INT_FAST16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST16_MAX);
	fprintf(outfile,"UINT_FAST16_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_FAST16_MAX);
	fprintf(outfile,"INT_FAST32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST32_MIN);
	fprintf(outfile,"INT_FAST32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST32_MAX);
	fprintf(outfile,"UINT_FAST32_MAX=%"PRIuMAX"\n",
		(U__Q8_MT)UINT_FAST32_MAX);
#ifdef	INT_FAST64_MAX
	fprintf(outfile,"INT_FAST64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST64_MIN);
	fprintf(outfile,"INT_FAST64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST64_MAX);
	fprintf(outfile,"UINT_FAST64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_FAST64_MAX);
#endif
#ifdef	INT_FAST128_MAX
	fprintf(outfile,"INT_FAST128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST128_MIN);
	fprintf(outfile,"INT_FAST128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST128_MAX);
	fprintf(outfile,"UINT_FAST128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_FAST128_MAX);
#endif
#ifdef	INTPTR_MAX
	fprintf(outfile,"INTPTR_MIN=%"PRIdMAX"\n", (__Q8_MT)INTPTR_MIN);
	fprintf(outfile,"INTPTR_MAX=%"PRIdMAX"\n", (__Q8_MT)INTPTR_MAX);
#endif
#ifdef	UINTPTR_MAX
	fprintf(outfile,"UINTPTR_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINTPTR_MAX);
#endif
#ifdef	INTMAX_MAX
	fprintf(outfile,"INTMAX_MIN=%"PRIdMAX"\n", (__Q8_MT)INTMAX_MIN);
	fprintf(outfile,"INTMAX_MAX=%"PRIdMAX"\n", (__Q8_MT)INTMAX_MAX);
	fprintf(outfile,"UINTMAX_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINTMAX_MAX);
#endif
#ifdef	PTRDIFF_MAX
	fprintf(outfile,"PTRDIFF_MIN=%"PRIdMAX"\n", (__Q8_MT)PTRDIFF_MIN);
	fprintf(outfile,"PTRDIFF_MAX=%"PRIdMAX"\n", (__Q8_MT)PTRDIFF_MAX);
#endif
#ifdef	SIG_ATOMIC_MAX
#if	SIG_ATOMIC_MIN < 0
	fprintf(outfile,"SIG_ATOMIC_MIN=%"PRIdMAX"\n", (__Q8_MT)SIG_ATOMIC_MIN);
	fprintf(outfile,"SIG_ATOMIC_MAX=%"PRIdMAX"\n", (__Q8_MT)SIG_ATOMIC_MAX);
#else
	fprintf(outfile,"SIG_ATOMIC_MIN=%"PRIuMAX"\n", (U__Q8_MT)SIG_ATOMIC_MIN);
	fprintf(outfile,"SIG_ATOMIC_MAX=%"PRIuMAX"\n", (U__Q8_MT)SIG_ATOMIC_MAX);
#endif
#endif
#ifdef	SIZE_MAX
	fprintf(outfile,"SIZE_MAX=%"PRIuMAX"\n", (U__Q8_MT)SIZE_MAX);
#endif

#ifdef	WCHAR_MAX
#if	WCHAR_MIN < 0
	fprintf(outfile,"WCHAR_MIN=%"PRIdMAX"\n", (__Q8_MT)WCHAR_MIN);
	fprintf(outfile,"WCHAR_MAX=%"PRIdMAX"\n", (__Q8_MT)WCHAR_MAX);
#else
	fprintf(outfile,"WCHAR_MIN=%"PRIuMAX"\n", (U__Q8_MT)WCHAR_MIN);
	fprintf(outfile,"WCHAR_MAX=%"PRIuMAX"\n", (U__Q8_MT)WCHAR_MAX);
#endif
#endif
#ifdef	WINT_MAX
#if	WINT_MIN < 0
	fprintf(outfile,"WINT_MIN=%"PRIdMAX"\n", (__Q8_MT)WINT_MIN);
	fprintf(outfile,"WINT_MAX=%"PRIdMAX"\n", (__Q8_MT)WINT_MAX);
#else
	fprintf(outfile,"WINT_MIN=%"PRIuMAX"\n", (U__Q8_MT)WINT_MIN);
	fprintf(outfile,"WINT_MAX=%"PRIuMAX"\n", (U__Q8_MT)WINT_MAX);
#endif
#endif

	/*
		7.18.4	Macros for integer constants
	*/

	/* INTn_C for n=8 and 16 were at one point unimplementable
	   on most platforms, so they're treated as "optional": */
#ifdef	INT8_C
	if ( INT8_C(-123) != -123 )
		fprintf(outfile,"*** INT8_C(-123) produced %"PRIdMAX" ***\n",
		       (__Q8_MT)INT8_C(-123)
		      );
	if ( UINT8_C(123) != 123 )
		fprintf(outfile,"*** UINT8_C(123) produced %"PRIuMAX" ***\n",
		       (U__Q8_MT)UINT8_C(123)
		      );
#endif
#ifdef	INT16_C
	if ( INT16_C(-12345) != -12345 )
		fprintf(outfile,"*** INT16_C(-12345) produced %"PRIdMAX" ***\n",
		       (__Q8_MT)INT16_C(-12345)
		      );
	if ( UINT16_C(12345) != 12345 )
		fprintf(outfile,"*** UINT16_C(12345) produced %"PRIuMAX" ***\n",
		       (U__Q8_MT)UINT16_C(12345)
		      );
#endif
	if ( INT32_C(-123456789) != -123456789 )
		fprintf(outfile,"*** INT32_C(-123456789) produced %"PRIdMAX" ***\n",
		       (__Q8_MT)INT32_C(-123456789)
		      );
	if ( UINT32_C(123456789) != 123456789 )
		fprintf(outfile,"*** UINT32_C(123456789) produced %"PRIuMAX" ***\n",
		       (U__Q8_MT)UINT32_C(123456789)
		      );
#ifdef	INT_LEAST64_MAX
	if ( INT64_C(-1234567890123456789) != -1234567890123456789 )
		fprintf(outfile,"*** INT64_C(-1234567890123456789) produced %"PRIdMAX
		       " ***\n",
		       (__Q8_MT)INT64_C(-1234567890123456789)
		      );
	if ( UINT64_C(1234567890123456789) != 1234567890123456789 )
		fprintf(outfile,"*** UINT64_C(1234567890123456789) produced %"PRIuMAX
		       " ***\n",
		       (U__Q8_MT)UINT64_C(1234567890123456789)
		      );
#endif
#ifdef	INTMAX_MAX
	if ( INTMAX_C(-1234567890123456789) != -1234567890123456789 )
		fprintf(outfile,"*** INTMAX_C(-1234567890123456789) produced %"PRIdMAX
		       " ***\n",
		       (__Q8_MT)INTMAX_C(-1234567890123456789)
		      );
	if ( UINTMAX_C(1234567890123456789) != 1234567890123456789 )
		fprintf(outfile,"*** UINTMAX_C(1234567890123456789) produced %"PRIuMAX
		       " ***\n",
		       (U__Q8_MT)UINTMAX_C(1234567890123456789)
		      );
#endif

	/* <inttypes.h> features: */

#if	__STDC_VERSION__ >= 199901
	fprintf(outfile,"sizeof(imaxdiv_t)=%u\n", (unsigned)sizeof(imaxdiv_t));
#endif

	/*
		7.8.1	Macros for format specifiers
	*/

	{
	/* scanf these strings */
	static const char	in_dn[] = "Z119bZ";
	static const char	in_dmo[] = "Z-0119bZ";
	static const char	in_dspx[] = "Z \t\n +0X119bZ";
	static const char	in_dsmx[] = "Z \t\n -0x119bZ";
	static const char	in_dsn[] = "Z \t\n 119bZ";
	static const char	in_dp[] = "Z+119bZ";
	static const char	in_dpx[] = "Z+0X119bz";

	/* sprintf into this */
	static char		buffer[1024];

#if 1

#define	SCAN(buf,fs,var,exp)	if ( sscanf(buf, "Z%" fs, &var) != 1 ) \
					{ \
					fprintf(outfile,"***%s=",fs, STR_SUB(fs) \
					       " failed ***\n" \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else if ( var != (exp) ) \
					{ \
					fprintf(outfile,"***%s=",fs,  STR_SUB(fs) \
					       " should be: " STR_SUB(exp) \
					       ", was: %" fs " ***\n", var \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else	/* for trailing semicolon */

#define	PRINT(fs,var,exp)	if ( sprintf(buffer, "%" fs, var ) <= 0 ) \
					{ \
					fprintf(outfile,"***%s=",fs, STR_SUB(fs) \
					       " failed ***\n" \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else if ( strcmp(buffer, STR_SUB(exp)) != 0 ) \
					{ \
					fprintf(outfile,"***%s=",fs,  STR_SUB(fs) \
					       " should be: " STR_SUB(exp) \
					       ", was: %s ***\n", buffer \
					      ); \
					status = EXIT_FAILURE; \
					} \
				else	/* for trailing semicolon */

#else
								 
#define	SCAN(buf,fs,var,exp)
#define	PRINT(fs,var,exp)

#endif
								 
#ifdef	SCNo32

	SCAN(in_dn, SCNo32, int32, 9);

#endif
#ifdef	PRIo32
	PRINT(PRIo32, int32, 11);
#endif
	SCAN(in_dmo, SCNiLEAST16, intl16, -9);
	SCAN(in_dspx, SCNdLEAST16, intl16, 0);
	SCAN(in_dsmx, SCNiLEAST16, intl16, -4507);
	PRINT(PRIdLEAST16, intl16, -4507);
	PRINT(PRIiLEAST16, intl16, -4507);
	SCAN(in_dsn, SCNxLEAST16, uintl16, 4507);
	PRINT(PRIoLEAST16, uintl16, 10633);
	PRINT(PRIuLEAST16, uintl16, 4507);
	PRINT(PRIxLEAST16, uintl16, 119b);
	PRINT(PRIXLEAST16, uintl16, 119B);
	SCAN(in_dp, SCNxFAST16, uintf16, 4507);
	PRINT(PRIxFAST16, uintf16, 119b);
#ifdef	SCNdMAX
	SCAN(in_dp, SCNdMAX, intmax, 119);
#endif
#ifdef	PRIiMAX
	PRINT(PRIiMAX, intmax, 119);
#endif
#ifdef	SCNoMAX
	SCAN(in_dpx, SCNoMAX, uintmax, 0);
#endif
#ifdef	PRIxMAX
	PRINT(PRIxMAX, uintmax, 0);
#endif
	/* Obviously there should be a much larger battery of such tests. */
	}

#if	defined(INTMAX_MAX)		/* <inttypes.h> has C99 features */
	/*
		7.8.2	Functions for greatest-width integer types
	*/

	{
	static struct
		{
		intmax_t	input;
		intmax_t	expect;
		}	abs_data[] =
		{
#ifdef	INT8_MAX
	  { INT8_MAX,		INT8_MAX,   },
	  { -INT8_MAX,		INT8_MAX,   },
	 { 	UINT8_MAX,		UINT8_MAX,  },
#endif

#if 0
  
#ifdef	INT16_MAX
	 { 	INT16_MAX,		INT16_MAX,  },
	 { 	-INT16_MAX,		INT16_MAX,  },
	 { 	UINT16_MAX,		UINT16_MAX, },
#endif
#ifdef	INT32_MAX
	 { 	INT32_MAX,		INT32_MAX,  },
	 { 	-INT32_MAX,		INT32_MAX,  },
#ifdef	INT_LEAST64_MAX			/* else might support only 32 bits */
	 { 	UINT32_MAX,		UINT32_MAX, },
#endif
#endif
#ifdef	INT64_MAX
	 { 	INT64_MAX,		INT64_MAX,  },
	 { 	-INT64_MAX,		INT64_MAX,  },
#endif
	 { 	INT_LEAST8_MAX,		INT_LEAST8_MAX,      },
	 { 	-INT_LEAST8_MAX,	INT_LEAST8_MAX,      },
	 { 	UINT_LEAST8_MAX,	UINT_LEAST8_MAX,     },
	 { 	INT_LEAST16_MAX,	INT_LEAST16_MAX,     },
	 { 	-INT_LEAST16_MAX,	INT_LEAST16_MAX,     },
	 { 	UINT_LEAST16_MAX,	UINT_LEAST16_MAX,    },
	 { 	INT_LEAST32_MAX,	INT_LEAST32_MAX,     },
	 { 	-INT_LEAST32_MAX,	INT_LEAST32_MAX,     },
#ifdef	INT_LEAST64_MAX
	 { 	UINT_LEAST32_MAX,	UINT_LEAST32_MAX,    },
	 { 	INT_LEAST64_MAX,	INT_LEAST64_MAX,     },
	 { 	-INT_LEAST64_MAX,	INT_LEAST64_MAX,     },
#endif
	 { 	INT_FAST8_MAX,		INT_FAST8_MAX,       },
	 { 	-INT_FAST8_MAX,	INT_FAST8_MAX,           },
	 { 	UINT_FAST8_MAX,	UINT_FAST8_MAX,          },
	 { 	INT_FAST16_MAX,	INT_FAST16_MAX,          },
	 { 	-INT_FAST16_MAX,	INT_FAST16_MAX,      },
	 { 	UINT_FAST16_MAX,	UINT_FAST16_MAX,     },
	 { 	INT_FAST32_MAX,	INT_FAST32_MAX,          },
	 { 	-INT_FAST32_MAX,	INT_FAST32_MAX,      },
#ifdef	INT_FAST64_MAX
	 { 	UINT_FAST32_MAX,	UINT_FAST32_MAX,     },
	 { 	INT_FAST64_MAX,	INT_FAST64_MAX,          },
	 { 	-INT_FAST64_MAX,	INT_FAST64_MAX,      },
#endif
#ifdef	INTPTR_MAX
	 { 	INTPTR_MAX,		INTPTR_MAX,              },
	 { 	-INTPTR_MAX,		INTPTR_MAX,          },
#endif
#ifdef	UINTPTR_MAX
	 { 	UINTPTR_MAX,		UINTPTR_MAX,         },
#endif
	 { 	INTMAX_MAX,		INTMAX_MAX,              },
#ifdef	PTRDIFF_MAX
	 { 	PTRDIFF_MAX,		PTRDIFF_MAX,         },
#endif
#ifdef	SIG_ATOMIC_MAX
	 { 	SIG_ATOMIC_MAX,		SIG_ATOMIC_MAX,      },
#if	SIG_ATOMIC_MIN < 0
	 { 	-SIG_ATOMIC_MAX,	SIG_ATOMIC_MAX,      },
#endif
#endif
#ifdef	SIZE_MAX
	 { 	SIZE_MAX,		SIZE_MAX,                },
#endif
#ifdef	WCHAR_MAX
	 { 	WCHAR_MAX,		WCHAR_MAX,               },
#if	WCHAR_MIN < 0
	 { 	-WCHAR_MAX,		WCHAR_MAX,               },
#endif
#endif
#ifdef	WINT_MAX
	 { 	WINT_MAX,		WINT_MAX,                },
#if	WINT_MIN < 0
	 {  -WINT_MAX,		WINT_MAX,                },
#endif
#endif
	 { 	127,				127,                 },
	 { 	-127,				127,                 },
	 { 	128,				128,                 },
	 { 	-127-1,				128,                 },
	 { 	255,				255,                 },
	 { 	-256+1,				255,                 },
	 { 	256,				256,                 },
	 { 	-256,				256,                 },
	 { 	32767,				32767,               },
	 { 	-32767,				32767,               },
	 { 	32768,				32768,               },
	 { 	-32767-1,			32768,               },
	 { 	65535,				65535,               },
	 { 	-65536+1,			65535,               },
	 { 	65536,				65536,               },
	 { 	-65536,				65536,               },
	 { 	2147483647,			2147483647,          },
	 { 	-2147483647,			2147483647,      },
	 { 	2147483648,			2147483648,          },
	 { 	-2147483647-1,			2147483648,      },
#ifdef	INT_LEAST64_MAX			/* else might support only 32 bits */
	 { 	4294967295,			4294967295,          },
	 { 	-4294967296+1,			4294967295,      },
	 { 	4294967296,			4294967296,          },
	 { 	-4294967296,			4294967296,      },
	 { 	9223372036854775807,		9223372036854775807,    },
	 { 	-9223372036854775807,		9223372036854775807,    },
	 { 	1234567890123456789,		1234567890123456789,    },
	 { 	-1234567890123456789,		1234567890123456789,    },
#endif
	 { 	1,				1,                                  },
	 { 	-1,				1,                                  },
	 { 	2,				2,                                  },
	 { 	-2,				2,                                  },
	 { 	10,				10,                                 },
	 { 	-10,				10,                             },
	 { 	16,				16,                                 },
	 { 	-16,				16,                             },
#endif
		/* Other test cases can be added here. */
	 { 	0,		0	/* terminates the list */              },
		},	*adp = abs_data;

	do	{
		if ( (intmax = imaxabs(adp->input)) != adp->expect )
			{
			fprintf(outfile,"*** imaxabs(%"PRIdMAX") failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n",
			       adp->input, adp->expect, intmax
			      );
			status = EXIT_FAILURE;
			}
//		} while ( adp++->input != 0 );
		} while ( (adp++)->input != 0 );
	}

	{
	imaxdiv_t	result;
	static struct
		{
		intmax_t	numer;
		intmax_t	denom;
		intmax_t	exp_quot;
		intmax_t	exp_rem;
		}	div_data[] =
		{
	{	0, 1,				0, 0,   },
#if 0
	{	0, -1,				0, 0,   },
	{	0, 2,				0, 0,   },
	{	0, -2,				0, 0,   },
	{	0, 5,				0, 0,   },
	{	0, -5,				0, 0,   },
	{	1, 1,				1, 0,   },
	{	1, -1,				-1, 0,  },
	{	1, 2,				0, 1,   },
	{	1, -2,				0, 1,   },
	{	1, 5,				0, 1,   },
	{	1, -5,				0, 1,   },
	{	-1, 1,				-1, 0,  },
	{	-1, -1,				1, 0,   },
	{	-1, 2,				0, -1,  },
	{	-1, -2,				0, -1,  },
	{	-1, 5,				0, -1,  },
	{	-1, -5,				0, -1,  },
	{	2, 1,				2, 0,   },
	{	2, -1,				-2, 0,  },
	{	2, 2,				1, 0,   },
	{	2, -2,				-1, 0,  },
	{	2, 5,				0, 2,   },
	{	2, -5,				0, 2,   },
	{	-2, 1,				-2, 0,  },
	{	-2, -1,				2, 0,   },
	{	-2, 2,				-1, 0,  },
	{	-2, -2,				1, 0,   },
	{	-2, 5,				0, -2,  },
	{	-2, -5,				0, -2,  },
	{	17, 5,				3, 2,   },
	{	-17, -5,			3, -2,  },
	{	17, -5,				-3, 2,  },
	{	-17, 5,				-3, -2, },
	{	2147483647, 1,			2147483647, 0,         },
	{	-2147483647, 1,			-2147483647, 0,        },
	{	2147483648, 1,			2147483648, 0,         },
	{	-2147483647-1, 1,		-2147483647-1, 0,      },
	{	2147483647, 2,			1073741823, 1,         },
	{	-2147483647, 2,			-1073741823, -1,       },
	{	2147483648, 2,			1073741824, 0,         },
	{	-2147483647-1, 2,		-1073741824, 0,        },
#ifdef	INT_LEAST64_MAX			/* else might support only 32 bits */
	{	4294967295, 1,			4294967295, 0,         },
	{	-4294967296+1, 1,		-4294967296+1, 0,      },
	{	4294967296, 1,			4294967296, 0,         },
	{	-4294967296, 1,			-4294967296, 0,        },
	{	4294967295, -1,			-4294967296+1, 0,      },
	{	-4294967296+1, -1,		4294967295, 0,         },
	{	4294967296, -1,			-4294967296, 0,        },
	{	-4294967296, -1,		4294967296, 0,         },
	{	4294967295, 2,			2147483647, 1,         },
	{	-4294967296+1, 2,		-2147483647, -1,       },
	{	4294967296, 2,			2147483648, 0,         },
	{	-4294967296, 2,			-2147483647-1, 0,      },
	{	4294967295, 2147483647,		2, 1,              },
	{	-4294967296+1, 2147483647,	-2, -1,            },
	{	4294967296, 2147483647,		2, 2,              },
	{	-4294967296, 2147483647,	-2, -2,            },
	{	4294967295, -2147483647,	-2, 1,             },
	{	-4294967296+1, -2147483647,	2, -1,             },
	{	4294967296, -2147483647,	-2, 2,             },
	{	-4294967296, -2147483647,	2, -2,             },
	{	4294967295, 2147483648,		1, 2147483647,     },
	{	-4294967296+1, 2147483648,	-1, -2147483647,   },
	{	4294967296, 2147483648,		2, 0,              },
	{	-4294967296, 2147483648,	-2, 0,             },
	{	4294967295, -2147483647-1,	-1, 2147483647,    },
	{	-4294967296+1, -2147483647-1,	1, -2147483647,},
	{	4294967296, -2147483647-1,	-2, 0,             },
	{	-4294967296, -2147483647-1,	2, 0,              },
	{	9223372036854775807, 1,		9223372036854775807, 0,         },
	{	-9223372036854775807, 1,	-9223372036854775807, 0,        },
	{	9223372036854775807, 2,		4611686018427387903, 1,         },
	{	-9223372036854775807, 2,	-4611686018427387903, -1,       },
#endif
#endif
		/* There should be a much larger battery of such tests. */
	{	0, 0,		0, 0 },	/* 0 denom terminates the list */
		},	*ddp;

#if 0
	for ( ddp = div_data; ddp->denom != 0; ++ddp )
		if ( (result = imaxdiv(ddp->numer, ddp->denom)).quot
		     != ddp->exp_quot || result.rem != ddp->exp_rem
		   )	{
//			fprintf(outfile,"*** imaxdiv(%"PRIdMAX",%"PRIdMAX
//			       ") failed; should be: (%"PRIdMAX",%"PRIdMAX
//			       "), was: (%"PRIdMAX",%"PRIdMAX") ***\n",
//			       ddp->numer, ddp->denom, ddp->exp_quot,
//			       ddp->exp_rem, result.quot, result.rem
//			      );
			fprintf(outfile,"err:imaxdiv(%"PRIdMAX",%"PRIdMAX
			       ") = (%"PRIdMAX",%"PRIdMAX
			       "), is: (%"PRIdMAX",%"PRIdMAX")\n",
			       ddp->numer, ddp->denom, ddp->exp_quot,
			       ddp->exp_rem, result.quot, result.rem
			      );
			status = EXIT_FAILURE;
			}
#endif
	}
	
	{
	char		*endptr;
	wchar_t		*wendptr;
	static char	saved[64];	/* holds copy of input string */
	static wchar_t	wnptr[64];	/* holds wide copy of test string */
	static int	warned;		/* "warned for null endptr" flag */
	register int	i;
	static struct
		{
		char *		nptr;
		int		base;
		intmax_t	exp_val;
		int		exp_len;
		}	str_data[] =
		{
	{	"", 0,				0, 0,      },
	{	"", 2,				0, 0,      },
	{	"", 8,				0, 0,      },
	{	"", 9,				0, 0,      },
	{	"", 10,				0, 0,      },
	{	"", 16,				0, 0,      },
	{	"", 36,				0, 0,      },
	{	"0", 0,				0, 1,      },
	{	"0", 2,				0, 1,      },
	{	"0", 8,				0, 1,      },
	{	"0", 9,				0, 1,      },
	{	"0", 10,			0, 1,      },
	{	"0", 16,			0, 1,      },
	{	"0", 36,			0, 1,      },
	{	"+0", 0,			0, 2,      },
	{	"+0", 2,			0, 2,      },
	{	"+0", 8,			0, 2,      },
	{	"+0", 9,			0, 2,      },
	{	"+0", 10,			0, 2,      },
	{	"+0", 16,			0, 2,      },
	{	"+0", 36,			0, 2,      },
	{	"-0", 0,			0, 2,      },
	{	"-0", 2,			0, 2,      },
	{	"-0", 8,			0, 2,      },
	{	"-0", 9,			0, 2,      },
	{	"-0", 10,			0, 2,      },
	{	"-0", 16,			0, 2,      },
	{	"-0", 36,			0, 2,      },
	{	"Inf", 0,			0, 0,      },
	{	"Inf", 2,			0, 0,      },
	{	"Inf", 8,			0, 0,      },
	{	"Inf", 9,			0, 0,      },
	{	"Inf", 10,			0, 0,      },
	{	"Inf", 16,			0, 0,      },
	{	"Inf", 36,			24171, 3,  },
	{	"+Inf", 0,			0, 0,      },
	{	"+Inf", 2,			0, 0,      },
	{	"+Inf", 8,			0, 0,      },
	{	"+Inf", 9,			0, 0,      },
	{	"+Inf", 10,			0, 0,      },
	{	"+Inf", 16,			0, 0,      },
	{	"+Inf", 36,			24171, 4,  },
	{	"-Inf", 0,			0, 0,      },
	{	"-Inf", 2,			0, 0,      },
	{	"-Inf", 8,			0, 0,      },
	{	"-Inf", 9,			0, 0,      },
	{	"-Inf", 10,			0, 0,      },
	{	"-Inf", 16,			0, 0,      },
	{	"-Inf", 36,			-24171, 4, },
	{	"inf", 0,			0, 0,      },
	{	"inf", 2,			0, 0,      },
	{	"inf", 8,			0, 0,      },
	{	"inf", 9,			0, 0,      },
	{	"inf", 10,			0, 0,      },
	{	"inf", 16,			0, 0,      },
	{	"inf", 36,			24171, 3,  },
	{	"+inf", 0,			0, 0,      },
	{	"+inf", 2,			0, 0,      },
	{	"+inf", 8,			0, 0,      },
	{	"+inf", 9,			0, 0,      },
	{	"+inf", 10,			0, 0,      },
	{	"+inf", 16,			0, 0,      },
	{	"+inf", 36,			24171, 4,  },
	{	"-inf", 0,			0, 0,      },
	{	"-inf", 2,			0, 0,      },
	{	"-inf", 8,			0, 0,      },
	{	"-inf", 9,			0, 0,      },
	{	"-inf", 10,			0, 0,      },
	{	"-inf", 16,			0, 0,      },
	{	"-inf", 36,			-24171, 4, },
	{	"119b8Z", 0,			119, 3,         },
	{	"119bZ", 0,			119, 3,             },
	{	"-0119bZ", 0,			-9, 4,          },
	{	" \t\n 0X119bZ", 0,		4507, 10,       },
	{	" \t\n +0X119bZ", 0,		4507, 11,   },
	{	" \t\n -0x119bZ", 0,		-4507, 11,  },
	{	" \t\n 119bZ", 0,		119, 7,         },
	{	"+119bZ", 0,			119, 4,         },
	{	"+0X119bz", 0,			4507, 7,        },
	{	"119b8Z", 2,			3, 2,           },
	{	"119bZ", 2,			3, 2,               },
	{	"-0119bZ", 2,			-3, 4,          },
	{	" \t\n 0X119bZ", 2,		0, 5,           },
	{	" \t\n +0X119bZ", 2,		0, 6,       },
	{	" \t\n -0x119bZ", 2,		0, 6,       },
	{	" \t\n 119bZ", 2,		3, 6,           },
	{	"+119bZ", 2,			3, 3,           },
	{	"+0X119bz", 2,			0, 2,           },
	{	"119b8Z", 8,			9, 2,           },
	{	"119bZ", 8,			9, 2,               },
	{	"-0119bZ", 8,			-9, 4,          },
	{	" \t\n 0X119bZ", 8,		0, 5,           },
	{	" \t\n +0X119bZ", 8,		0, 6,       },
	{	" \t\n -0x119bZ", 8,		0, 6,       },
	{	" \t\n 119bZ", 8,		9, 6,           },
	{	"+119bZ", 8,			9, 3,           },
	{	"+0X119bz", 8,			0, 2,           },
	{	"119b8Z", 9,			10, 2,          },
	{	"119bZ", 9,			10, 2,              },
	{	"-0119bZ", 9,			-10, 4,         },
	{	" \t\n 0X119bZ", 9,		0, 5,           },
	{	" \t\n +0X119bZ", 9,		0, 6,       },
	{	" \t\n -0x119bZ", 9,		0, 6,       },
	{	" \t\n 119bZ", 9,		10, 6,          },
	{	"+119bZ", 9,			10, 3,          },
	{	"+0X119bz", 9,			0, 2,           },
	{	"119b8Z", 10,			119, 3,         },
	{	"119bZ", 10,			119, 3,         },
	{	"-0119bZ", 10,			-119, 5,        },
	{	" \t\n 0X119bZ", 10,		0, 5,       },
	{	" \t\n +0X119bZ", 10,		0, 6,       },
	{	" \t\n -0x119bZ", 10,		0, 6,       },
	{	" \t\n 119bZ", 10,		119, 7,         },
	{	"+119bZ", 10,			119, 4,         },
	{	"+0X119bz", 10,			0, 2,           },
	{	"119b8Z", 16,			72120, 5,       },
	{	"119bZ", 16,			4507, 4,        },
	{	"-0119bZ", 16,			-4507, 6,       },
	{	" \t\n 0X119bZ", 16,		4507, 10,   },
	{	" \t\n +0X119bZ", 16,		4507, 11,   },
	{	" \t\n -0x119bZ", 16,		-4507, 11,  },
	{	" \t\n 119bZ", 16,		4507,8,         },
	{	"+119bZ", 16,			4507, 5,        },
	{	"+0X119bz", 16,			4507, 7,        },
	{	"119b8Z", 36,			62580275, 6,    },
	{	"119bZ", 36,			1738367, 5,     },
	{	"-0119bZ", 36,			-1738367, 7,                 },
	{	" \t\n 0X119bZ", 36,		1997122175, 11,          },
	{	" \t\n +0X119bZ", 36,		1997122175, 12,          },
	{	" \t\n -0x119bZ", 36,		-1997122175, 12,         },
	{	" \t\n 119bZ", 36,		1738367, 9,                  },
	{	"+119bZ", 36,			1738367, 6,                  },
	{	"+0X119bz", 36,			1997122175, 8,               },
	 	/* There should be a much larger battery of such tests. */
	{	"127", 0,			127, 3,                          },
	{	"-127", 0,			-127, 4,                         },
	{	"128", 0,			128, 3,                          },
	{	"-128", 0,			-127-1, 4,                       },
	{	"255", 0,			255, 3,                          },
	{	"-255", 0,			-255, 4,                         },
	{	"256", 0,			256, 3,                          },
	{	"-256", 0,			-255-1, 4,                       },
	{	"32767", 0,			32767, 5,                        },
	{	"-32767", 0,			-32767, 6,                   },
	{	"32768", 0,			32768, 5,                        },
	{	"-32768", 0,			-32767-1, 6,                 },
	{	"65535", 0,			65535, 5,                        },
	{	"-65535", 0,			-65536+1, 6,                 },
	{	"65536", 0,			65536, 5,                        },
	{	"-65536", 0,			-65536, 6,                   },
	{	"2147483647", 0,		2147483647, 10,              },
	{	"-2147483647", 0,		-2147483647, 11,             },
	{	"2147483648", 0,		2147483648, 10,              },
	{	"-2147483648", 0,		-2147483647-1, 11,           },
	{	"4294967295", 0,		4294967295, 10,              },
	{	"-4294967295", 0,		-4294967296+1, 11,           },
	{	"4294967296", 0,		4294967296, 10,              },
	{	"-4294967296", 0,		-4294967296, 11,                        },
	{	"9223372036854775807", 0,	9223372036854775807, 19,            },
	{	"-9223372036854775807", 0,	-9223372036854775807, 20,           },
	{	"1234567890123456789", 0,	1234567890123456789, 19,            },
	{	"-1234567890123456789", 0,	-1234567890123456789, 20,           },
	{	"1", 0,				1, 1,                                       },
	{	"-1", 0,			-1, 2,                                      },
	{	"2", 0,				2, 1,                                       },
	{	"-2", 0,			-2, 2,                                      },
	{	"10", 0,			10, 2,                                      },
	{	"-10", 0,			-10, 3,                                     },
	{	"16", 0,			16, 2,                                      },
	{	"-16", 0,			-16, 3,                                     },
		/* Other test cases can be added here. */
	{	NULL, 0,	0, 0 },	/* terminates the list */
		},	*sdp;

	for ( sdp = str_data; sdp->nptr != NULL ; ++sdp )
		{
		/*
			7.8.2.3	The strtoimax and strtoumax functions
		*/

		strcpy(saved, sdp->nptr);

		errno = 0;		/* shouldn't be changed */

		if ( (intmax = strtoimax(sdp->nptr, &endptr, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			fprintf(outfile,"*** strtoimax(%s,,%d) failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
			       sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}
		else if ( endptr != sdp->nptr + sdp->exp_len )
			{
			int	save = errno;

			fprintf(outfile,"*** strtoimax(%s,,%d) returned wrong endptr"
			       " ***\n", sdp->nptr, sdp->base
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			fprintf(outfile,"*** strtoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		if ( strcmp(sdp->nptr, saved) != 0 )
			{
			fprintf(outfile,"*** strtoimax modified its input ***\n");
			status = EXIT_FAILURE;
			strcpy(saved, sdp->nptr);
			}

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = strtoumax(sdp->nptr, &endptr, sdp->base
						 )
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				fprintf(outfile,"*** strtoumax(%s,,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}
			else if ( endptr != sdp->nptr + sdp->exp_len )
				{
				int	save = errno;

				fprintf(outfile,"*** strtoumax(%s,,%d) returned wrong "
				       "endptr ***\n", sdp->nptr, sdp->base
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			if ( errno != 0 )
				{
				fprintf(outfile,"*** strtoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			if ( strcmp(sdp->nptr, saved) != 0 )
				{
				fprintf(outfile,"*** strtoumax"
				       " modified its input ***\n"
				      );
				status = EXIT_FAILURE;
				strcpy(saved, sdp->nptr);
				}
			}

		/* tests for null endptr */

#define	WARN()	if (!warned) warned = 1, fprintf(outfile,"*** Using null endptr: ***\n")

		warned = 0;
		errno = 0;		/* shouldn't be changed */

		if ( (intmax = strtoimax(sdp->nptr, (char **)NULL, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			WARN();
			fprintf(outfile,"*** strtoimax(%s,NULL,%d) failed; "
			       "should be: %"PRIdMAX", was: %"PRIdMAX" ***\n",
			       sdp->nptr, sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			WARN();
			fprintf(outfile,"*** strtoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		if ( strcmp(sdp->nptr, saved) != 0 )
			{
			WARN();
			fprintf(outfile,"*** strtoimax modified its input ***\n");
			status = EXIT_FAILURE;
			strcpy(saved, sdp->nptr);
			}

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = strtoumax(sdp->nptr, (char **)NULL,
						  sdp->base
						 )
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				WARN();
				fprintf(outfile,"*** strtoumax(%s,NULL,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			 if ( errno != 0 )
				{
				WARN();
				fprintf(outfile,"*** strtoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			 if ( strcmp(sdp->nptr, saved) != 0 )
				{
				WARN();
				fprintf(outfile,"*** strtoumax"
				       " modified its input ***\n"
				      );
				status = EXIT_FAILURE;
				strcpy(saved, sdp->nptr);
				}
			}

		/*
			7.8.2.4	The wcstoimax and wcstoumax functions
		*/

		for ( i = 0; i < 64; ++i )
			if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
				break;

		errno = 0;		/* shouldn't be changed */

		if ( (intmax = wcstoimax(wnptr, &wendptr, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			fprintf(outfile,"*** wcstoimax(%s,,%d) failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
			       sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}
		else if ( wendptr != wnptr + sdp->exp_len )
			{
			int	save = errno;

			fprintf(outfile,"*** wcstoimax(%s,,%d) returned wrong endptr"
			       " ***\n", sdp->nptr, sdp->base
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			fprintf(outfile,"*** wcstoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		for ( i = 0; i < 64; ++i )
			if ( wnptr[i] != sdp->nptr[i] )
				{
				fprintf(outfile,"*** wcstoimax modified its input ***\n"
				      );
				status = EXIT_FAILURE;

				for ( ; i < 64; ++i )
					if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
						break;

				break;
				}
			else if ( wnptr[i] == '\0' )
				break;

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = wcstoumax(wnptr, &wendptr, sdp->base)
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				fprintf(outfile,"*** wcstoumax(%s,,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}
			else if ( wendptr != wnptr + sdp->exp_len )
				{
				int	save = errno;

				fprintf(outfile,"*** wcstoumax(%s,,%d) returned wrong "
				       "endptr ***\n", sdp->nptr, sdp->base
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			if ( errno != 0 )
				{
				fprintf(outfile,"*** wcstoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			for ( i = 0; i < 64; ++i )
				if ( wnptr[i] != sdp->nptr[i] )
					{
					fprintf(outfile,"*** wcstoumax"
					       " modified its input ***\n"
					      );
					status = EXIT_FAILURE;

					for ( ; i < 64; ++i )
						if ( (wnptr[i] = sdp->nptr[i])
						  == '\0'
						   )
							break;

					break;
					}
				else if ( wnptr[i] == '\0' )
					break;
			}

		/* tests for null endptr */

		warned = 0;
		errno = 0;		/* shouldn't be changed */

		if ( (intmax = wcstoimax(wnptr, (wchar_t **)NULL, sdp->base))
		  != sdp->exp_val
		   )	{
			int	save = errno;

			WARN();
			fprintf(outfile,"*** wcstoimax(%s,NULL,%d) failed; should be: %"
			       PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
			       sdp->base, sdp->exp_val, intmax
			      );
			status = EXIT_FAILURE;
			errno = save;
			}

		if ( errno != 0 )
			{
			WARN();
			fprintf(outfile,"*** wcstoimax modified errno ***\n");
			status = EXIT_FAILURE;
			}

		for ( i = 0; i < 64; ++i )
			if ( wnptr[i] != sdp->nptr[i] )
				{
				WARN();
				fprintf(outfile,"*** wcstoimax modified its input ***\n"
				      );
				status = EXIT_FAILURE;

				for ( ; i < 64; ++i )
					if ( (wnptr[i] = sdp->nptr[i])
					  == '\0'
					   )
						break;

				break;
				}
			else if ( wnptr[i] == '\0' )
				break;

		if ( sdp->exp_val >= 0 )	/* else some sign extension */
			{
			errno = 0;	/* shouldn't be changed */

			if ( (uintmax = wcstoumax(wnptr, (wchar_t **)NULL,
						  sdp->base
						 )
			     ) != sdp->exp_val
			   )	{
				int	save = errno;

				WARN();
				fprintf(outfile,"*** wcstoumax(%s,NULL,%d) failed; "
				       "should be: %"PRIuMAX", was: %"PRIuMAX
				       " ***\n", sdp->nptr, sdp->base,
				       sdp->exp_val, uintmax
				      );
				status = EXIT_FAILURE;
				errno = save;
				}

			 if ( errno != 0 )
				{
				WARN();
				fprintf(outfile,"*** wcstoumax modified errno ***\n");
				status = EXIT_FAILURE;
				}

			for ( i = 0; i < 64; ++i )
				if ( wnptr[i] != sdp->nptr[i] )
					{
					WARN();
					fprintf(outfile,"*** wcstoumax"
					       " modified its input ***\n"
					      );
					status = EXIT_FAILURE;

					for ( ; i < 64; ++i )
						if ( (wnptr[i] = sdp->nptr[i])
						  == '\0'
						   )
							break;

					break;
					}
				else if ( wnptr[i] == '\0' )
					break;
			}
		}

	/*
		7.8.2.3	The strtoimax and strtoumax functions (continued)
	*/

	if ( (intmax = strtoimax("1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoimax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = strtoimax("+1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoimax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = strtoimax("-1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != INTMAX_MIN || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoimax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = strtoumax("1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoumax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = strtoumax("+1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoumax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = strtoumax("-1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890"
				 "1234567890123456789012345678901234567890",
				 &endptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** strtoumax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}

	/*
		7.8.2.4	The wcstoimax and wcstoumax functions (continued)
	*/

#ifdef NO_INTERNAL_WCHAR
		fprintf(outfile,"NO_INTERNAL_WCHAR\n");
#else

	if ( (intmax = wcstoimax(L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoimax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = wcstoimax(L"+1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != INTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoimax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (intmax = wcstoimax(L"-1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != INTMAX_MIN || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoimax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = wcstoumax(L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoumax failed overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = wcstoumax(L"+1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoumax failed +overflow test ***\n");
		status = EXIT_FAILURE;
		}

	if ( (uintmax = wcstoumax(L"-1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890"
				 L"1234567890123456789012345678901234567890",
				 &wendptr, 0
				)
	     ) != UINTMAX_MAX || errno != ERANGE
	   )	{
		fprintf(outfile,"*** wcstoumax failed -overflow test ***\n");
		status = EXIT_FAILURE;
		}
#endif // NO_INTERNAL_WCHAR
	}
#endif	/* defined(INTMAX_MAX) */

	if ( status != 0 )
		fprintf(outfile, "sitest failed.\n");

    CLOSETEST();
	
	return status;
}
Exemple #16
0
// clang-format off
intmax_t (imaxabs)(intmax_t i) {
  return imaxabs(i);
}
Exemple #17
0
void
inttypes (__INTMAX_TYPE__ j)
{
  imaxabs (j); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..inttypes.h.." "" { target *-*-* } 266 } */
}
Exemple #18
0
int serialise_int(char* dest, int size, int64_t value)
{
    assert(dest != NULL);
    assert(size > 0);

    char result[INT_BUF_SIZE] = "";
    int length = 0;

    if (value == 0)
    {
        result[0] = '0';
    }
    else
    {
        const bool is_negative = (value < 0);

        // Make sure we can get an absolute value
        const bool is_smallest = (value == INT64_MIN);
        const int64_t safe_value = is_smallest ? value + 1 : value;

        const int64_t abs_value = imaxabs(safe_value);

        // Write digits and sign in reverse order
        int64_t left = abs_value;
        while (left != 0)
        {
            assert(length < INT_BUF_SIZE);

            int64_t digit = left % 10;
            result[length] = digit + '0';

            left /= 10;
            ++length;
        }

        if (is_negative)
        {
            assert(length < INT_BUF_SIZE);
            result[length] = '-';
            ++length;
        }

        // Fix smallest value
        if (is_smallest)
        {
            assert(result[0] != '9'); // magnitude is a power of 2
            result[0] += 1;
        }

        // Reverse contents
        for (int i = 0; i < length / 2; ++i)
        {
            int other_index = length - i - 1;
            char tmp = result[i];
            result[i] = result[other_index];
            result[other_index] = tmp;
        }
    }

    int printed = snprintf(dest, size, "%s", result);

    return min(printed, size - 1);
}