|
Packit |
80c72f |
/* tnorm -- test file for mpc_norm.
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
Copyright (C) 2008, 2011 INRIA
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
This file is part of GNU MPC.
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
GNU MPC is free software; you can redistribute it and/or modify it under
|
|
Packit |
80c72f |
the terms of the GNU Lesser General Public License as published by the
|
|
Packit |
80c72f |
Free Software Foundation; either version 3 of the License, or (at your
|
|
Packit |
80c72f |
option) any later version.
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
Packit |
80c72f |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
Packit |
80c72f |
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
Packit |
80c72f |
more details.
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
80c72f |
along with this program. If not, see http://www.gnu.org/licenses/ .
|
|
Packit |
80c72f |
*/
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
#include "mpc-tests.h"
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
static void
|
|
Packit |
80c72f |
test_underflow (void)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
mpfr_exp_t emin = mpfr_get_emin ();
|
|
Packit |
80c72f |
mpc_t z;
|
|
Packit |
80c72f |
mpfr_t f;
|
|
Packit |
80c72f |
int inex;
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
mpfr_set_emin (-1); /* smallest positive number is 0.5*2^emin = 0.25 */
|
|
Packit |
80c72f |
mpc_init2 (z, 10);
|
|
Packit |
80c72f |
mpfr_set_ui_2exp (mpc_realref (z), 1023, -11, GMP_RNDN); /* exact */
|
|
Packit |
80c72f |
mpfr_set_ui_2exp (mpc_imagref (z), 1023, -11, GMP_RNDN); /* exact */
|
|
Packit |
80c72f |
mpfr_init2 (f, 10);
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
inex = mpc_norm (f, z, GMP_RNDZ); /* should give 511/1024 */
|
|
Packit |
80c72f |
if (inex >= 0)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
printf ("Error in underflow case (1)\n");
|
|
Packit |
80c72f |
printf ("expected inex < 0, got %d\n", inex);
|
|
Packit |
80c72f |
exit (1);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
if (mpfr_cmp_ui_2exp (f, 511, -10) != 0)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
printf ("Error in underflow case (1)\n");
|
|
Packit |
80c72f |
printf ("got ");
|
|
Packit |
80c72f |
mpfr_dump (f);
|
|
Packit |
80c72f |
printf ("expected ");
|
|
Packit |
80c72f |
mpfr_set_ui_2exp (f, 511, -10, GMP_RNDZ);
|
|
Packit |
80c72f |
mpfr_dump (f);
|
|
Packit |
80c72f |
exit (1);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
inex = mpc_norm (f, z, GMP_RNDN); /* should give 511/1024 */
|
|
Packit |
80c72f |
if (inex >= 0)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
printf ("Error in underflow case (2)\n");
|
|
Packit |
80c72f |
printf ("expected inex < 0, got %d\n", inex);
|
|
Packit |
80c72f |
exit (1);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
if (mpfr_cmp_ui_2exp (f, 511, -10) != 0)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
printf ("Error in underflow case (2)\n");
|
|
Packit |
80c72f |
printf ("got ");
|
|
Packit |
80c72f |
mpfr_dump (f);
|
|
Packit |
80c72f |
printf ("expected ");
|
|
Packit |
80c72f |
mpfr_set_ui_2exp (f, 511, -10, GMP_RNDZ);
|
|
Packit |
80c72f |
mpfr_dump (f);
|
|
Packit |
80c72f |
exit (1);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
inex = mpc_norm (f, z, GMP_RNDU); /* should give 1023/2048 */
|
|
Packit |
80c72f |
if (inex <= 0)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
printf ("Error in underflow case (3)\n");
|
|
Packit |
80c72f |
printf ("expected inex > 0, got %d\n", inex);
|
|
Packit |
80c72f |
exit (1);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
if (mpfr_cmp_ui_2exp (f, 1023, -11) != 0)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
printf ("Error in underflow case (3)\n");
|
|
Packit |
80c72f |
printf ("got ");
|
|
Packit |
80c72f |
mpfr_dump (f);
|
|
Packit |
80c72f |
printf ("expected ");
|
|
Packit |
80c72f |
mpfr_set_ui_2exp (f, 1023, -11, GMP_RNDZ);
|
|
Packit |
80c72f |
mpfr_dump (f);
|
|
Packit |
80c72f |
exit (1);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
mpc_clear (z);
|
|
Packit |
80c72f |
mpfr_clear (f);
|
|
Packit |
80c72f |
mpfr_set_emin (emin);
|
|
Packit |
80c72f |
}
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
int
|
|
Packit |
80c72f |
main (void)
|
|
Packit |
80c72f |
{
|
|
Packit |
80c72f |
DECL_FUNC (FC, f, mpc_norm);
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
test_start ();
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
data_check (f, "norm.dat");
|
|
Packit |
80c72f |
tgeneric (f, 2, 1024, 1, 4096);
|
|
Packit |
80c72f |
test_underflow ();
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
test_end ();
|
|
Packit |
80c72f |
|
|
Packit |
80c72f |
return 0;
|
|
Packit |
80c72f |
}
|