实现近似计算公式
| 5 | #include <algorithm> |
| 6 | // 实现近似计算公式 |
| 7 | double approx_exp(double x, int r = 8) { |
| 8 | if (x > 0) return 0; // 只处理 x <= 0 的情况 |
| 9 | |
| 10 | double base = 1.0 + x / (256); |
| 11 | double result = base; |
| 12 | |
| 13 | // 计算2^r次方 |
| 14 | for (int i = 0; i < r; i++) { |
| 15 | result *= result; |
| 16 | } |
| 17 | |
| 18 | return result; |
| 19 | } |
| 20 | |
| 21 | double pade_approximation(double x) { |
| 22 | if (x > 0) return 0; |
nothing calls this directly
no outgoing calls
no test coverage detected