@@ -155,12 +155,20 @@ class MPCNumber {
155155
156156 MPCNumber carg () const {
157157 mpfr_t res;
158+ mpc_t res_mpc;
159+
158160 mpfr_init2 (res, this ->mpc_real_precision );
161+ mpc_init3 (res_mpc, this ->mpc_real_precision , this ->mpc_imag_precision );
162+
159163 mpc_arg (res, value, MPC_RND_RE (this ->mpc_rounding ));
160- mpc_t res_mpc;
161- mpc_set_fr (res_mpc, res, MPC_RND_RE (this ->mpc_rounding ));
162- return MPCNumber (res_mpc, this ->mpc_real_precision ,
163- this ->mpc_imag_precision , this ->mpc_rounding );
164+ mpc_set_fr (res_mpc, res, this ->mpc_rounding );
165+
166+ MPCNumber result (res_mpc, this ->mpc_real_precision , this ->mpc_imag_precision , this ->mpc_rounding );
167+
168+ mpfr_clear (res);
169+ mpc_clear (res_mpc);
170+
171+ return result;
164172 }
165173};
166174
@@ -215,8 +223,10 @@ bool compare_unary_operation_single_output_different_type(
215223 MPCNumber mpc_result;
216224 mpc_result = unary_operation (op, input, precision, rounding);
217225 mpc_t mpc_result_val;
226+ mpc_init3 (mpc_result_val, precision, precision);
218227 mpc_result.getValue (mpc_result_val);
219228 mpfr_t real;
229+ mpfr_init2 (real, precision);
220230 mpc_real (real, mpc_result_val, get_mpfr_rounding_mode (rounding.Rrnd ));
221231 mpfr::MPFRNumber mpfr_real (real, precision, rounding.Rrnd );
222232 double ulp_real = mpfr_real.ulp (libc_result);
@@ -227,6 +237,42 @@ template bool compare_unary_operation_single_output_different_type(
227237 Operation, _Complex float , float , double , MPCRoundingMode);
228238template bool compare_unary_operation_single_output_different_type (
229239 Operation, _Complex double , double , double , MPCRoundingMode);
240+
241+ template <typename InputType, typename OutputType>
242+ void explain_unary_operation_single_output_different_type_error (
243+ Operation op, InputType input, OutputType libc_result, double ulp_tolerance,
244+ MPCRoundingMode rounding) {
245+
246+ unsigned int precision = get_precision<get_real_t <InputType>>(ulp_tolerance);
247+
248+ MPCNumber mpc_result;
249+ mpc_result = unary_operation (op, input, precision, rounding);
250+
251+ mpc_t mpc_result_val;
252+ mpc_init3 (mpc_result_val, precision, precision);
253+ mpc_result.getValue (mpc_result_val);
254+
255+ mpfr_t real;
256+ mpfr_init2 (real, precision);
257+ mpc_real (real, mpc_result_val, get_mpfr_rounding_mode (rounding.Rrnd ));
258+
259+ mpfr::MPFRNumber mpfr_real (real, precision, rounding.Rrnd );
260+
261+ double ulp_real = mpfr_real.ulp (libc_result);
262+
263+ if (ulp_real > ulp_tolerance) {
264+ cpp::array<char , 1024 > msg_buf;
265+ cpp::StringStream msg (msg_buf);
266+ // TODO: Add information to the error message.
267+ }
268+
269+ }
270+
271+ template void explain_unary_operation_single_output_different_type_error (
272+ Operation, _Complex float , float , double , MPCRoundingMode);
273+ template void explain_unary_operation_single_output_different_type_error (
274+ Operation, _Complex double , double , double , MPCRoundingMode);
275+
230276} // namespace internal
231277
232278} // namespace mpc
0 commit comments