Comment by tzs
4 days ago
In that Padé approximant I think you can save a couple multiplications.
As written it does this:
n = 1 - 367/714 * x**2
d = 1 - 81/119 * x**2 + 183/4760 * x**4
return x * (n/d)
That's got 7 multiplies (I'm counting divide as a multiply) and 3 additions. (I'm assuming the optimizer only computes x^2 once and computes x^2 by squaring x^2, and that all the constants are calculated at compile time).
Replace n/d with 1/(d/n) and then replace d/n with q + r/n where q is the quotient of polynomial d divided by polynomial n and r is the remainder.
This is the result:
n = 1 - 367/714 * x**2
q = 1587627/1346890 - 549/7340 * x**2
r = -240737/1346890
return x / (q + r/n)
That's got 5 multiplies and 3 additions.
No comments yet
Contribute on Hacker News ↗