On Fri, Jan 4, 2019 at 2:49 PM John Maddock via Boost
On 04/01/2019 18:24, Matt Pulver via Boost wrote:
Hello,
Regarding the page Conceptual Requirements for Real Number Types
https://www.boost.org/doc/libs/1_69_0/libs/math/doc/html/math_toolkit/real_c...
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
Library.
Perhaps this is just old documentation, or I am not looking in the
right
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
https://github.com/boostorg/math/blob/d26f04a9c9e3004904dd466249ddf84eae76ec...
from
return 0;
to
return static_cast