Submitted by __141345__
AdaptiveFee.sol#L70-L108
The evaluation of exp function will be inaccurate, and further affect the accuracy of sigmoid() function, eventually affecting fee calculation.
Also the calculation takes quite a lot of gas to calculate to 8th term.
x/g takes value between 0 to 6, but taylor expansion maintains good approximation only near 0. When x/g is close to 5, the error is around 7% for exp() and 7% forsigmoid() respectively. When x/g is close to 6, the error could go up to 15% for exp() and 18% for sigmoid().
The value of exp(1), exp(2), exp(3), exp(4), exp(5), exp(6) can be pre-calculated and saved to constants, then be used as denominator or multiplier.
For example, to calculate exp(3.48), what we can do is calculate exp(0.48), and then multiply by exp(3).
When the power is less than 0.5, taylor expansion up to x^3 can give good accuracy. exp(0.5) and corresponding sigmoid() has maximum error in the order of 2e-4 to 1e-4.
vladyan18 (QuickSwap & StellaSwap) acknowledged and commented:
0xean (judge) commented:
