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)?
In the implementation, the
si
variants are very simple functions based on theui
functions:src/si_op.c
. So the first reason thesj
variants are not provided is because theuj
variants are not provided.Now, the most basic
ui
variants (likempfr_mul_ui
andmpfr_add_ui
) were added in 1999 and 2000, in the first year of the MPFR development. The firstintmax_t
based functions were added only in 2004 (mpfr_set_
ones, andmpfr_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 theui
andsi
variants. Additional variants could be added in the future, but this is not done yet.Note that the
TODO
currently hasSuch functions would at least be useful internally. But other variants could be added too.