summaryrefslogtreecommitdiff
path: root/tests/check_data.c
blob: 33ffcb17d41c7f0e98d7549896f4b7a3401190b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* check_data.c -- Check computed data against reference result.

Copyright (C) 2012, 2013 INRIA

This file is part of GNU MPC.

GNU MPC is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see http://www.gnu.org/licenses/ .
*/

#include "templates.h"

#define MPC_INEX_CMP(c, r, i)                                 \
  (((r) == TERNARY_NOT_CHECKED || (r) == MPC_INEX_RE(c))      \
   && ((i) == TERNARY_NOT_CHECKED || (i) == MPC_INEX_IM (c)))

static int
check_param  (mpc_operand_t* got, mpc_operand_t* expected, mpc_param_t t)
{
  switch (t)
    {
    case NATIVE_INT:
      return got->i == expected->i;
    case NATIVE_UL:
      return got->ui == expected->ui;
    case NATIVE_L:
      return got->si == expected->si;
    case NATIVE_D:
      return got->d == expected->d;

    case GMP_Z:
      return mpz_cmp (got->mpz, expected->mpz);
    case GMP_Q:
      return mpq_cmp (got->mpq, expected->mpq);
    case GMP_F:
      return mpf_cmp (got->mpf, expected->mpf);

    case MPFR_INEX:
      return expected->mpfr_inex == TERNARY_NOT_CHECKED
        || got->mpfr_inex == expected->mpfr_inex;

    case MPFR:
      return tpl_check_mpfr_data (got->mpfr,
                                  expected->mpfr_data);

    case MPC_INEX:
      return MPC_INEX_CMP (got->mpc_inex,
                           expected->mpc_inex_data.real,
                           expected->mpc_inex_data.imag);

    case MPC:
      return tpl_check_mpc_data (got->mpc,
                                 expected->mpc_data);

    default:
      fprintf (stderr, "check_data: unsupported type.\n");
      exit (1);
    }
}

void
check_data (mpc_datafile_context_t* dc, mpc_fun_param_t* params, int reused_op)
{
  int out, i;
  int total = params->nbout + params->nbin;

  for (out = 0; out < params->nbout; out++)
    {
      if (!check_param (&(params->P[out]), &(params->P[total + out]),
                        params->T[out]))
        {
          printf ("%s() failed", params->name);
          if (dc != NULL)
            printf (" (line %lu, file %s)",
                    dc->test_line_number, dc->pathname);
          else
            printf (" with random parameter%c",
                    params->nbin > 2 ? 's' : '\0');

          if (reused_op != 0)
            printf (" when reusing input parameter op%d as output parameter",
                    reused_op - params->nbout);
          printf ("\n");

          for (i = 0; i < params->nbin; i++)
            {
              printf ("op%d", i + 1);
              print_parameter (params, params->nbout + i);
            }

          for (i = 0; i < params->nbout; i++)
            {
              if ((params->T[i] == MPFR_INEX && params->T[out] != MPFR_INEX)
                  || (params->T[i] == MPC_INEX && params->T[out] != MPC_INEX))
                continue; /* don't print inexact flag if it is correct */

              printf ("     got%c",
                      (total + i > params->nbout ? '\0' : i + '0'));
              print_parameter (params, i);
              printf ("expected%c",
                      (total + i > params->nbout ? '\0' : i + '0'));
              print_parameter (params, total + i);
            }
          printf ("\n");
          exit (1);
        }
    }
}