Skip to main content

Unknown parent

Devine Lu Linvega
@esther sqrt(), sorry not trig
in reply to Devine Lu Linvega

Everything about this is just super cool, the shape, the patterns, the fact that it's sqrt-less... and the mix with the music is just 👩‍🍳💋!
in reply to Devine Lu Linvega

Nifty! I've been doing an approximate `sqrt(n)` recently with this iterative approach:
a = n
for 1..m:
a = (a + n / a) / 2

So I tried this using your approach for an initial guess:
a = max(abs(x),abs(y)) + min(abs(x),abs(y))/2;
s = x*x + y*y;
if (a != 0.0) {
a = (a + s / a) / 2;
a = (a + s / a) / 2;
}

Within a range of -100 to 100 this takes your approximation from a max error of about 34% to a max error of 0.4%. The average error goes from 9% to 0.4%.

It's still just 7% max error and 0.4% average error if you only do one iteration.

Sorry, no fancy visualisations, but here’s a picture of them both overlayed (I considered a “they're the same picture" meme instead):

Unknown parent

Devine Lu Linvega
@hikari it looks very similar, is it the same thing?
in reply to Devine Lu Linvega

If you scale by 15/16 (which is very simple with integers!), you get an average better result:
https://flylib.com/books/en/2.729.1/high_speed_vector_magnitude_approximation.html

Lo, thar be cookies on this site to keep track of your login. By clicking 'okay', you are CONSENTING to this.