]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make Utilities::pow() available for floating point types.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 9 Jan 2024 20:31:48 +0000 (13:31 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 9 Jan 2024 20:31:48 +0000 (13:31 -0700)
include/deal.II/base/utilities.h

index 30dc5684b6e70b30f6387dfe99b446933767fbc3..5c5a1252ece1ac63c994261de523ae33001419f7 100644 (file)
@@ -437,12 +437,15 @@ namespace Utilities
   T
   fixed_power(const T t);
 
+
   /**
    * A replacement for <code>std::pow</code> that allows compile-time
-   * calculations for constant expression arguments. The @p base must
-   * be an integer type and the exponent @p iexp must not be negative.
+   * calculations for constant expression arguments and if the exponent
+   * is a positive integer. The @p base must be an arithmetic type
+   * (i.e., an integer or floating point type),
+   * and the exponent @p iexp must not be negative.
    */
-  template <typename T>
+  template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
   constexpr DEAL_II_HOST_DEVICE T
   pow(const T base, const int iexp)
   {
@@ -477,8 +480,6 @@ namespace Utilities
 #    endif
 #  endif
 #endif
-    static_assert(std::is_integral_v<T>, "Only integral types supported");
-
     // The "exponentiation by squaring" algorithm used below has to be expressed
     // in an iterative version since SYCL doesn't allow recursive functions used
     // in device code.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.