mdickinson / bigfloat

Python wrapper for MPFR, providing high-precision floating-point arithmetic
GNU Lesser General Public License v3.0
41 stars 11 forks source link

add support for mpfr_get_z_2exp #80

Open programmerjake opened 5 years ago

programmerjake commented 5 years ago

We (libre-riscv.org) are thinking of using bigfloat to test a hardware floating-point implementation. It would be useful to be able to extract the exact value as a python2 long/python3 int since that's probably much more efficient than using conversion to/from string for each conversion.

mdickinson commented 4 years ago

Apologies for the (very) late response; you've probably already figured out that this library doesn't get as frequently maintained as it should, and moved on.

But in case you haven't: mpfr_get_z_2exp wouldn't be all that easy to implement in this library, since we'd need to add support for the GMP integer type, and then conversions to and from that type to Python's bigint type; currently, bigfloat doesn't know anything about GMP mpz objects.

Have you looked at gmpy2? That probably does everything you need.

programmerjake commented 4 years ago

Apologies for the (very) late response; you've probably already figured out that this library doesn't get as frequently maintained as it should, and moved on.

No problem, I ended up writing my own implementation of IEEE 754.

But in case you haven't: mpfr_get_z_2exp wouldn't be all that easy to implement in this library, since we'd need to add support for the GMP integer type, and then conversions to and from that type to Python's bigint type; currently, bigfloat doesn't know anything about GMP mpz objects.

Ok.

mdickinson commented 4 years ago

Not closing this issue, because it would make sense to have analogues of the various get and set methods that work with Python long integers; but it's unlikely that the most convenient / efficient way to implement those would be through the existing get_z / set_z functions.

I'd also need to figure out the right names to use; if we have a function mpfr_get_z_2exp that returns a Python integer (and exponent), that would preclude adding a genuine wrapper for mpfr_get_z_2exp at a later date. So we need something other than "z" to represent a Python integer. mpfr_get_pi_2exp? mpfr_get_y_2exp?

programmerjake commented 4 years ago

maybe mpfr_get_pyint_2exp?

mpfr_get_pi_2exp seems confusing due to confusing pi with the mathematical constant π.