Why there is no mpfr_sub_sj (while there is mpfr_set_sj_2exp)?

31 Views Asked by At

A simple question: why there is no mpfr_sub_sj (while there is mpfr_set_sj_2exp)?

More details: for mpfr_set_xx_2exp there are sj and uj variants:

$ grep -P 'int mpfr_set_.*_2exp' mpfr.h
__MPFR_DECLSPEC int mpfr_set_z_2exp (mpfr_ptr, mpz_srcptr, mpfr_exp_t,
__MPFR_DECLSPEC int mpfr_set_si_2exp (mpfr_ptr, long, mpfr_exp_t, mpfr_rnd_t);
__MPFR_DECLSPEC int mpfr_set_ui_2exp (mpfr_ptr, unsigned long, mpfr_exp_t,
__MPFR_DECLSPEC int mpfr_set_sj_2exp (mpfr_ptr, intmax_t, intmax_t,
__MPFR_DECLSPEC int mpfr_set_uj_2exp (mpfr_ptr, uintmax_t, intmax_t,

However, for mpfr_sub_xx there are no sj and uj variants:

$ grep -P 'mpfr_sub_' mpfr.h
__MPFR_DECLSPEC int mpfr_sub_q (mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t);
__MPFR_DECLSPEC int mpfr_sub_ui (mpfr_ptr, mpfr_srcptr, unsigned long,
__MPFR_DECLSPEC int mpfr_sub_si (mpfr_ptr, mpfr_srcptr, long, mpfr_rnd_t);
__MPFR_DECLSPEC int mpfr_sub_d (mpfr_ptr, mpfr_srcptr, double, mpfr_rnd_t);
__MPFR_DECLSPEC int mpfr_sub_z (mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t);

Why? Will it be useful to have sj and uj variants for mpfr_sub_xx (and others)?

1

There are 1 best solutions below

4
On BEST ANSWER

In the implementation, the si variants are very simple functions based on the ui functions: src/si_op.c. So the first reason the sj variants are not provided is because the uj variants are not provided.

Now, the most basic ui variants (like mpfr_mul_ui and mpfr_add_ui) were added in 1999 and 2000, in the first year of the MPFR development. The first intmax_t based functions were added only in 2004 (mpfr_set_ ones, and mpfr_get_ ones a few months later). The initial goal was just to be able to do conversions, which is sufficient for most needs: by choosing an adequate precision, one can do an exact conversion to a MPFR number, then the wanted operation similar to the ui and si variants. Additional variants could be added in the future, but this is not done yet.

Note that the TODO currently has

- mpfr_cmp_uj, mpfr_cmp_sj, mpfr_mul_uj, mpfr_mul_sj. They would be useful
  to test MPFR with _MPFR_EXP_FORMAT=4.
  Note: the code sometimes uses mpfr_cmp_si with __gmpfr_emin or __gmpfr_emax;
  this is incorrect when _MPFR_EXP_FORMAT=4.

Such functions would at least be useful internally. But other variants could be added too.