BioCMAMC-ST
maths.hpp
1#ifndef __BIOMC_COMMON_MATHS__
2#define __BIOMC_COMMON_MATHS__
3
4#include <Kokkos_BitManipulation.hpp>
5#include <Kokkos_MathematicalFunctions.hpp>
6
7namespace CommonMaths
8{
9
10 template <bool use_kokkos_log>
11 KOKKOS_INLINE_FUNCTION float
12 _ln(float x)
13 requires(!use_kokkos_log)
14 {
15 // NOLINTBEGIN
16 // std::bit_cast keeps the same exact bit in the target type
17 // better than unsafe C const
18 unsigned int bx = Kokkos::bit_cast<unsigned int>(x);
19 const unsigned int ex = bx >> 23;
20 const signed int t
21 = static_cast<signed int>(ex) - static_cast<signed int>(127);
22 // unsigned int s = (t < 0) ? (-t) : t;
23 bx = 1065353216 | (bx & 8388607);
24 x = Kokkos::bit_cast<float>(bx);
25 return -1.49278 + (2.11263 + (-0.729104 + 0.10969 * x) * x) * x
26 + 0.6931471806 * t;
27 // NOLINTEND
28 }
29
30 template <bool use_kokkos_log>
31 KOKKOS_INLINE_FUNCTION float
32 _ln(float x)
33 requires(use_kokkos_log)
34 {
35 return Kokkos::log(x);
36 }
37
38} // namespace CommonMaths
39#endif
Definition maths.hpp:8
KOKKOS_INLINE_FUNCTION float _ln(float x)
Definition maths.hpp:12