boostorg / boostorg/multiprecision

Conversion to interval

Open
#108 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
265
Forks
128
Avg merge
4h 48m
Merged PRs (30d)
2

Description

Hello,
in our application, we regularly convert a bignum `x` to an interval of double `(i,s)`, similar to what Boost.Interval provides, such that `i<=x<=s`. With Boost.Multiprecision, to convert to an interval, I can first convert to a double `d`, cross my fingers that the conversion was within 1 ulp (should be true for most types), then return the interval `(nextafter(d,-inf), nextafter(d,+inf))`. However, in many places, we have a fast path for the case where the interval is a point. This means that, if the bignum happens to fit exactly in a `double` (unlikely in general, but quite common in some applications), it is important for us to get a tight interval `(d, d)`.
For `mpz_int` or `mpq_rational`, a way to do that is to access `x.backend().data()` and use MPFR for the conversion.
For `cpp_int` or `cpp_rational`, I don't know how to get a tight interval. Well, I can actually think of some ways (for instance convert `cpp_int` to double and back to `cpp_int` and compare to the original, etc), but they are going to be ugly and slow compared to something using the internals of `cpp_int`. It would be ideal if Boost.Multiprecision provided, at least for `cpp_int`, a tight conversion to `boost::numeric::interval`, or a conversion to `double` that also lets the user know if this was rounded up, down, or exact (so I know which bound of the interval requires `nextafter`).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.