Boost logo

Boost :

From: Gero Peterhoff (g.peterhoff_at_[hidden])
Date: 2023-03-10 21:11:22


Hello,
* Problem description
The constants do not work with the C++23 FP types.

* general hint
To prevent (more) warnings it is useful to introduce this macro:
#if defined(__STDCPP_FLOAT128_T__)
        #define BOOST_FLOATMAX_SUFFIX F128
#elif defined(BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE)
        #define BOOST_FLOATMAX_SUFFIX Q
#else
        #define BOOST_FLOATMAX_SUFFIX L
#endif

* question
In constants the namespaces float/double/long_double_constant+detail are created type dependent (in case the value constexpr can be requested). If the value cannot be requested constexpr the conversion is finally done by boost::lexical_cast.
But the implementation is very complex. I have a better one - but I may have missed things.
If so - which would they be?

* My solution (BOOST_MAKE_MATH_CONSTANT)
see constants_more.hpp, advantages:
- works with all FP types
- compatible to the existing implementation CONSTANT<Type>()
- is clear/understandable (comments)
- may need only one additional namespace static_constants (and not 4)
- provides the constants additionally as CONSTANT_v (constexpr) or static_constants::CONSTANT_v (not constexpr) (if possible)

What is your opinion? Are there still errors in it?

It would be even nicer if boost::lexical_cast and/or boost::math::tools::convert_from_string were constexpr. This would further simplify the implementation.

thx + regards
Gero








Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk