Subject: Re: [boost] iround() and itrunc() in Conceptual Requirements for Real Number Types
From: Matt Pulver (mpulver_at_[hidden])
Date: 2019-01-04 20:50:31
On Fri, Jan 4, 2019 at 2:49 PM John Maddock via Boost <boost_at_[hidden]>
> On 04/01/2019 18:24, Matt Pulver via Boost wrote:
> > Hello,
> > Regarding the page Conceptual Requirements for Real Number Types
> > Is it still accurate to list these 2 rows under Standard Library Support
> > Requirements?
> > - iround(cr1) | int
> > - itrunc(cr1) | int
> > The motivation in asking this is two-fold:
> > 1. I don't see either of these functions listed in the Standard
> > Perhaps this is just old documentation, or I am not looking in the
> > place. Instead, I do find lround() and truncl().
> I should make it clearer that these are not *std* lib functions -
> they're Boost.Math functions, but will be called via ADL so can be in
> the same namespace as the number type.
I should have checked there.
The motivation for these, is that there are many special functions which
> require conversion of the real-number-type to an integer as part of
> their implementation (when figuring out recurrence relations for
> example). However, conversion of arbitrary number types to integers
> can't be guaranteed, and when it does work - as with built in floating
> point types - then it's unsafe (overflow etc). So these functions
> provide a customisation point for this conversion.
> You may well find that Boost.Math's default versions of these work for
> your number type - have you tried it to see?
I just did, and found I had to make a couple of minor modifications to get
boost::math::iround() to work:
1. Added an explicit int() operator to the autodiff class.
2. Changed line 38 of round.hpp
No changes were needed to trunc.hpp since a similar
static_cast<result_type>() is already done there.
This is because in the particular case of autodiff, the single-parameter
constructors are declared explicit. I can attempt to justify this design
choice if this seems questionable.
I'm happy to submit a pull request for this change if you like.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk