Révision 140 pobysoC-4.0/src/pobyso.c

pobyso.c (revision 140)
39 39
  sollya_lib_autoprint(objSo, NULL);
40 40
} /* End pobyso_autoprint. */
41 41

  
42
/* @see pobyso.h#pobyso_evaluate_constant */
42 43
int
43 44
pobyso_evaluate_constant(pobyso_func_exp_t functionSo,
44 45
                          mpfr_t argumentMp,
45 46
                          mpfr_t evaluationMp)
46 47
{
47
  int outcome = 0;
48 48
  sollya_obj_t argumentSo   = NULL;
49 49
  sollya_obj_t evaluationSo = NULL;
50
  mpfr_t evaluationTmpMp    = NULL;
50
  mpfr_t evaluationTmpMp1;
51
  mpfr_t evaluationTmpMp2;
52
  mpfr_prec_t evalPrec      = 0;
51 53

  
52 54
  /* Test argument. */
53 55
  if (functionSo == NULL || argumentMp == NULL || evaluationMp == NULL)
......
64 66
                     "The functionSo argument is not a functional expression");
65 67
    return 1;
66 68
  }
69
  /* Function evaluation and checks. */
67 70
  argumentSo    = sollya_lib_constant(argumentMp);
68 71
  evaluationSo  = sollya_lib_evaluate(functionSo, argumentSo);
69
  //TODO: finish this function!
70
  // Check evaluationSo.
71
  // Depending on its type and value, convert to a MPFR number and/or
72
  // return an error value.
73 72
  sollya_lib_clear_obj(argumentSo);
74
  sollya_lib_clear_obj(evaluationSo);
75
  return 0;
73
  /* The range case: we return the mean of the bounds. The result
74
   * is not faithfully rounded. */
75
  if (sollya_lib_obj_is_range(evaluationSo))
76
  {
77
    if (sollya_lib_get_prec_of_range(&evalPrec, evaluationSo))
78
    {
79
      mpfr_init2(evaluationTmpMp1, evalPrec);
80
      mpfr_init2(evaluationTmpMp2, evalPrec);
81
      if (sollya_lib_get_bounds_from_range(evaluationTmpMp1,
82
                                       evaluationTmpMp2,
83
                                       evaluationSo))
84
      {
85
        /* Compute the mean of the bounds. */
86
        mpfr_clear(evaluationMp);
87
        mpfr_init2(evaluationMp, evalPrec);
88
        mpfr_add(evaluationMp,evaluationTmpMp1,evaluationTmpMp2,MPFR_RNDN);
89
        mpfr_div_2ui(evaluationMp, evaluationMp, 1, MPFR_RNDN);
90
        mpfr_clear(evaluationTmpMp1);
91
        mpfr_clear(evaluationTmpMp2);
92
        sollya_lib_clear_obj(evaluationSo);
93
        return POBYSO_UNFAITHFULL;
94
      }
95
      else /* Could not get the values of the bounds. */
96
      {
97
        sollya_lib_clear_obj(evaluationSo);
98
        return 1;
99
      }
100
    }
101
    else /* Could not get the precision of the range. */
102
    {
103
      sollya_lib_clear_obj(evaluationSo);
104
      return 1;
105
    }
106
  } /* End the evaluation is a range. */
107
  /* From now on, we assume that the evaluation is constant. */
108
  if (sollya_lib_get_prec_of_range(&evalPrec, evaluationSo))
109
  {
110
    mpfr_init2(evaluationTmpMp1, evalPrec);
111
    if (sollya_lib_get_constant(evaluationTmpMp1, evaluationSo))
112
    {
113
      /* Deal with the NaN case. */
114
      if (mpfr_nan_p(evaluationTmpMp1))
115
      {
116
        mpfr_clear(evaluationTmpMp1);
117
        sollya_lib_clear_obj(evaluationSo);
118
        return POBYSO_NAN;
119
      }
120
      else /* The evaluation is not NaN. */
121
      {
122
        mpfr_clear(evaluationMp);
123
        mpfr_init2(evaluationMp, evalPrec);
124
        mpfr_set(evaluationMp, evaluationTmpMp1, MPFR_RNDN);
125
        mpfr_clear(evaluationTmpMp1);
126
        sollya_lib_clear_obj(evaluationSo);
127
        return 0;
128
      }
129
    }
130
    else /* Could not recover the value of the evaluation. */
131
    {
132
      mpfr_clear(evaluationTmpMp1);
133
      sollya_lib_clear_obj(evaluationSo);
134
      return 1;
135
    }
136
  }
137
  else /* Could not get the precision of the evaluation. */
138
  {
139
    sollya_lib_clear_obj(evaluationSo);
140
    return 0;
141
  }
76 142
}
77 143
/* End pobyso_evaluate_constant. */
78 144

  

Formats disponibles : Unified diff