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) requires(!use_kokkos_log)
12 {
13 // NOLINTBEGIN
14 unsigned int bx = *reinterpret_cast<unsigned int*>(&x);
15 const unsigned int ex = bx >> 23;
16 const signed int t
17 = static_cast<signed int>(ex) - static_cast<signed int>(127);
18 // unsigned int s = (t < 0) ? (-t) : t;
19 bx = 1065353216 | (bx & 8388607);
20 x = *reinterpret_cast<float*>(&bx);
21 return -1.49278 + (2.11263 + (-0.729104 + 0.10969 * x) * x) * x
22 + 0.6931471806 * t;
23 // NOLINTEND
24 }
25
26 template <bool use_kokkos_log>
27 KOKKOS_INLINE_FUNCTION float
28 _ln(float x) requires(use_kokkos_log)
29 {
30 return Kokkos::log(x);
31 }
32
33} // namespace CommonMaths
34#endif
Definition maths.hpp:7
KOKKOS_INLINE_FUNCTION float _ln(float x)
Definition maths.hpp:11