Standalone exp implementation using Taylor series e^x ≈ 1 + x + x²/2! + x³/3! + x⁴/4! + ...
| 78 | // Standalone exp implementation using Taylor series |
| 79 | // e^x ≈ 1 + x + x²/2! + x³/3! + x⁴/4! + ... |
| 80 | float 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 | |
| 101 | double exp_impl_double(double value) { |
| 102 | if (value > 10.0) |
no outgoing calls
no test coverage detected