MCPcopy Create free account
hub / github.com/catboost/catboost / FastLog2f

Function FastLog2f

library/cpp/fast_log/fast_log.h:62–76  ·  view source on GitHub ↗

* @returns Base 2 logarithm of the value. * This is fast, inline and quite accurate algorithm. * Accuracy: ~1.e-5 * Speed: ~3x over logf() * Source: https://code.google.com/archive/p/fastapprox/ * Description: http://www.machinedlearnings.com/2011/06/fast-approximate-logarithm-exponential.html */

Source from the content-addressed store, hash-verified

60 * Description: http://www.machinedlearnings.com/2011/06/fast-approximate-logarithm-exponential.html
61 */
62static inline float FastLog2f(float value) noexcept {
63 Y_ASSERT(LogInputCheck(value));
64 union {
65 float f;
66 ui32 i;
67 } vx = {value};
68 union {
69 ui32 i;
70 float f;
71 } mx = {(vx.i & 0x007FFFFF) | 0x3f000000};
72 float y = vx.i;
73 y *= 1.1920928955078125e-7f;
74
75 return y - 124.22551499f - 1.498030302f * mx.f - 1.72587999f / (0.3520887068f + mx.f);
76}
77
78/**
79 * @returns Base e logarithm of the value.

Callers 1

FastLogfFunction · 0.85

Calls 1

LogInputCheckFunction · 0.85

Tested by

no test coverage detected