chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Feature Request]: GMP Module mpf_t string support

Open s-timcheck opened this issue 9 months ago • 1 comments

Summary of Feature

Description:

The GMP Module does not have support for getting strings of the mpf_t type, unlike the facilities it has for mpz_t. There exists chpl_gmp_mpz_get_str which uses mpz_get_str, but neither chpl_gmp_mpf_get_str or mpf_get_str are implemented in the current version of Chapel, so there is no way to get a string conversion for the mpf_t type. This will probably require adding mp_exp_t as well?

Is this a blocking issue with no known work-arounds?

The only workaround I see for printing mpf_t vars is redefining gmp_printf where the args parameter has the designated intent of const ref:

extern proc gmp_printf(fmt: c_ptrConst(c_char), const ref arg ...);

The designated intent is probably an issue for the mpz_t type too.

Code Sample

I would like to be able to do something like below:

var x:mpf_t;
mpf_init(x);
mpf_set_d(x, 0.123456789);

var s:c_ptrConst(c_char) = mpf_get_str(s, 1, 10, 4, x); //string s, exponent of 1, base 10, print 4 digits, mpf_t operand

s-timcheck avatar May 20 '24 18:05 s-timcheck