|
Boost Users : |
Subject: Re: [Boost-users] generalize boost macros
From: John Maddock (jz.maddock_at_[hidden])
Date: 2019-02-03 09:10:07
> That's exactly my problem.
>
> namespace std
> {
> // declare missing log2, cannot say constexpr: compilererror
> inline float128_t log2(const float128_t& arg) noexcept
> {
> return log2q(arg);
> }
> }
There's no conceivable way we can implement that as a constexpr algorithm.
>
> // also not constexpr
> inline float128_t myfunc(const float128_t& arg) noexcept
> {
> // log2_e not available
> // constexpr float128_t factor =
> boost::math::constants::log2_e<float128_t>();
>
> // compiler generates a function call to log2
> const float128_t factor =
> std::log2(boost::math::constants::e<float128_t>());
>
> return arg*factor;
> }
log2(e) == 1/log(2)
So:
constexpr float128_t log2_e = 1 /
boost::math::constants::ln_two<float128_t>();
does actually work just fine.
Note that we cannot provide every single conceivable constant, so you
can also define your own:
namespace boost {
  namespace math {
     namespace constants {
        BOOST_DEFINE_MATH_CONSTANT(log2_e,
1.4426950408889634073599246810018921374266459541529859341,
"1.4426950408889634073599246810018921374266459541529859341354494069311092191811850798855266228935063444969975183096");
     }
  }
}
Which is also constepxr for float128_t.
--- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net