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

Function exp_impl_float

src/fl/math/math.cpp.hpp:80–99  ·  view source on GitHub ↗

Standalone exp implementation using Taylor series e^x ≈ 1 + x + x²/2! + x³/3! + x⁴/4! + ...

Source from the content-addressed store, hash-verified

78// Standalone exp implementation using Taylor series
79// e^x ≈ 1 + x + x²/2! + x³/3! + x⁴/4! + ...
80float exp_impl_float(float value) {
81 if (value > 10.0f)
82 return 22026.465794806718f; // e^10 approx
83 if (value < -10.0f)
84 return 0.0000453999297625f; // e^-10 approx
85
86 // For negative values, use exp(x) = 1/exp(-x) to keep the Taylor series
87 // input non-negative where it converges well with limited terms.
88 if (value < 0.0f) {
89 return 1.0f / exp_impl_float(-value);
90 }
91
92 float result = 1.0f;
93 float term = 1.0f;
94 for (int i = 1; i < 10; ++i) {
95 term *= value / static_cast<float>(i);
96 result += term;
97 }
98 return result;
99}
100
101double exp_impl_double(double value) {
102 if (value > 10.0)

Callers 3

pow_impl_floatFunction · 0.85
expfFunction · 0.85
expFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected