#include "log2_ln.hpp" #include #include namespace soothe2 { float ln_plugin_f32(float x) { if (x <= 0.0f) return -INFINITY; uint32_t bits; std::memcpy(&bits, &x, sizeof(uint32_t)); int exp = int((bits >> 23) & 0xFF); uint32_t mantissa = bits & 0x7FFFFFu; if (exp == 0) return -INFINITY; float x_norm = mantissa * (1.0f / 8388608.0f); constexpr float c0_a = -0.1517720520f; constexpr float c0_b = 0.1696488112f; constexpr float c1 = -0.1646245718f; constexpr float c2 = 0.1982250363f; constexpr float c3 = -0.2500466406f; constexpr float c4 = 0.3333656490f; constexpr float c5 = -0.5000000000f; constexpr float ln2 = 0.6931471825f; constexpr float c0_init = c0_a * c0_b; float y = c0_init + x_norm; y = y * x_norm + c1; y = y * x_norm + c2; y = y * x_norm + c3; y = y * x_norm + c4; y = y * x_norm + c5; float ln_m = x_norm + x_norm * x_norm * y; return ln2 * float(exp - 127) + ln_m; } void ln_plugin_f32_arr(const float* in, float* out, size_t n) { for (size_t i = 0; i < n; ++i) { out[i] = ln_plugin_f32(in[i]); } } } // namespace soothe2