MCPcopy Create free account
hub / github.com/FastLED/FastLED / fast_logf_approx

Function fast_logf_approx

src/fl/math/math.h:406–415  ·  view source on GitHub ↗

log (natural) - fast approximate version Uses IEEE 754 bit extraction + minimax quadratic. ~1.5% max relative error. ~5-10x faster than standard logf on embedded targets.

Source from the content-addressed store, hash-verified

404// Uses IEEE 754 bit extraction + minimax quadratic. ~1.5% max relative error.
405// ~5-10x faster than standard logf on embedded targets.
406inline float fast_logf_approx(float x) FL_NOEXCEPT {
407 union { float f; u32 i; } u;
408 u.f = x;
409 i32 e = static_cast<i32>(u.i >> 23) - 127;
410 u.i = (u.i & 0x007FFFFFu) | 0x3F800000u;
411 float m = u.f;
412 float t = m - 1.0f;
413 float log2m = t * (1.3327635f + t * (-0.3327635f));
414 return (static_cast<float>(e) + log2m) * 0.6931471805599453f;
415}
416
417// log (natural)
418inline float logf(float value) FL_NOEXCEPT { return log_impl_float(value); }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected