From b5d925de98720a8a8e6f03d482bab8a22903d30a Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 6 Jul 2020 19:29:28 +0100 Subject: [PATCH] Minor update for pow(): Add a few more constexpr tests for the corner cases. Document the constexpr-ness. See https://github.com/boostorg/math/issues/354. --- doc/sf/pow.qbk | 8 ++++++-- test/pow_test.cpp | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/sf/pow.qbk b/doc/sf/pow.qbk index b349ace09..db021978e 100644 --- a/doc/sf/pow.qbk +++ b/doc/sf/pow.qbk @@ -10,10 +10,10 @@ power of a run-time base. namespace boost { namespace math { template - ``__sf_result`` pow(T base); + constexpr ``__sf_result`` pow(T base); template - ``__sf_result`` pow(T base, const Policy& policy); + constexpr ``__sf_result`` pow(T base, const Policy& policy); }} @@ -60,6 +60,10 @@ For example: * If T is a `long double`, the return type is a `long double`. * Otherwise, the return type is a `double`. +[h4 constexpr] + +This function is usable in `constexpr` contexts from C++14 onwards. + [h4 Policies] [optional_policy] diff --git a/test/pow_test.cpp b/test/pow_test.cpp index eef8e3e6d..6c45d893b 100644 --- a/test/pow_test.cpp +++ b/test/pow_test.cpp @@ -196,6 +196,10 @@ BOOST_AUTO_TEST_CASE( test_main ) #ifndef BOOST_NO_CXX14_CONSTEXPR static_assert(boost::math::pow<8>(2)==256, "Pow is not constexpr"); + static_assert(boost::math::pow<9>(2)==512, "Pow is not constexpr"); + static_assert(boost::math::pow<2>(2)==4, "Pow is not constexpr"); + static_assert(boost::math::pow<1>(2)==2, "Pow is not constexpr"); + static_assert(boost::math::pow<0>(2)==1, "Pow is not constexpr"); #endif test_return_types();