Home | History | Annotate | Line # | Download | only in tests
      1 /* init_parameters -- Allocate memory for function parameters.
      2 
      3 Copyright (C) 2012, 2014 INRIA
      4 
      5 This file is part of GNU MPC.
      6 
      7 GNU MPC is free software; you can redistribute it and/or modify it under
      8 the terms of the GNU Lesser General Public License as published by the
      9 Free Software Foundation; either version 3 of the License, or (at your
     10 option) any later version.
     11 
     12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
     13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
     15 more details.
     16 
     17 You should have received a copy of the GNU Lesser General Public License
     18 along with this program. If not, see http://www.gnu.org/licenses/ .
     19 */
     20 
     21 #include <stdio.h>
     22 #include "mpc-tests.h"
     23 
     24 static void
     25 init_param (mpc_operand_t* p, mpc_param_t t)
     26 {
     27   switch (t)
     28     {
     29     case NATIVE_INT:
     30     case NATIVE_UL:
     31     case NATIVE_L:
     32     case NATIVE_D:
     33       break;
     34 
     35     case GMP_Z:
     36       mpz_init (p->mpz);
     37       break;
     38     case GMP_Q:
     39       mpq_init (p->mpq);
     40       break;
     41     case GMP_F:
     42       mpf_init (p->mpf);
     43       break;
     44 
     45     case MPFR_INEX:
     46       break;
     47     case MPFR:
     48       mpfr_init2 (p->mpfr, 512);
     49       break;
     50 
     51     case MPC_INEX:
     52     case MPCC_INEX:
     53       break;
     54     case MPC:
     55       mpc_init2 (p->mpc, 512);
     56       break;
     57 
     58     case MPFR_RND:
     59     case MPC_RND:
     60       break;
     61 
     62     default:
     63       fprintf (stderr, "init_parameters: unsupported type.\n");
     64       exit (1);
     65     }
     66 }
     67 
     68 void
     69 init_parameters (mpc_fun_param_t *params)
     70 {
     71   int in, out;
     72   int total = params->nbout + params->nbin;
     73 
     74   for (out = 0; out < params->nbout; out++)
     75     {
     76       init_param (&(params->P[out]), params->T[out]);
     77       init_param (&(params->P[total + out]), params->T[total + out]);
     78     }
     79 
     80   for (in = params->nbout; in < total; in++)
     81     {
     82       init_param (&(params->P[in]), params->T[in]);
     83     }
     84 }
     85