Donut.c Without a Math Library
a1k0n.net
a1k0n.net
It's the main idea of the classic CORDIC algorithm (as mentioned by the author), used to be the most popular way to implement sin() and cos() on early underpowered calculators. https://en.wikipedia.org/wiki/CORDIC#Rotation_mode
I feel trying these things opens a lot of avenues, that many people close for themselves, because they would ask: "but why on earth would I do this?".
The power of because-i-can is strong.
It's beautiful. Keep up the good w-, ehm fun. :)
Explainer: https://codeexplainer.wordpress.com/2017/08/27/underscore-pi...
There's no need to use Sympy, it's kind of overkill. If f(x) = 1/x^2 - a, then f'(x) = -2x^-3. You can find x_new easily:
x_new = x - f(x) / f'(x)
= x - (1/x^2 - a) / (-2x^-3)
= x + (1/2) (x^3) (1/x^2 - a)
= x + (1/2) (x - ax^3)
= (3x - ax^3) / 2
= x(3 - ax^2) / 2I think the built-in code generator is a bit strange, though: for example, it always prints integers as integers, and not as floats depending on the context, so code often doesn't typecheck.
Works out of the box on AmigaOS 3.1 compiled with bebbo's gcc fork.