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