From d9a10a7d07eeda6b4493e8799dc10eb95e02ea75 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 8 Jun 2025 16:14:18 -0700 Subject: [PATCH] fastest sqrt version, fix percentage --- magnitest.p8 | 26 ++++++++++++++++++++++---- profiling.p8 | 5 +++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/magnitest.p8 b/magnitest.p8 index f7cbbf6..3a3c88f 100644 --- a/magnitest.p8 +++ b/magnitest.p8 @@ -22,6 +22,16 @@ function bbs28999algopt(dx, dy) return (n*n + 1)^0.5 * d end +-- profiler says 54 cycles +-- 26 lua, 28 system +function bbs28999algopt2(dx, dy) + local d,n=abs(dx),abs(dy) + if (d 1024) acc=1024 local a,b=abs(gdx),abs(gdy) if (b>a) a,b=b,a magnitude = 1 - while magnitude*64 < a do + while magnitude < a/64 do magnitude *= 2 end - bresult=bbs28999algopt(gdx,gdy) + bresult=bbs28999algopt2(gdx,gdy) tresult=trigalg(gdx,gdy) delta=tresult-bresult + dp=(2*abs(delta)/abs(abs(bresult)+abs(tresult)))*100 + if (delta == 0) dp=0 end cols = { @@ -81,11 +97,13 @@ cols = { function _draw() cls() + camera() + print("x: "..tostr(gdx).." y: "..tostr(gdy).."\nbase: "..tostr(bresult).."\ntrig: "..tostr(tresult).."\n\ndiff: "..tostr(delta).."\n %:"..tostr(dp),0,0,13) + print("⬆️⬇️⬅️➡️:move ❎:fast 🅾️:slow\n❎+🅾️:reset position",0,117,12) camera(-63,-63) line(0,0,gdx/magnitude,gdy/magnitude,cols[magnitude] or 2) rectfill(0,0,gdx/magnitude,0,5) rectfill(0,0,0,gdy/magnitude,5) - print("x: "..tostr(gdx).." y: "..tostr(gdy).."\nbase: "..tostr(bresult).."\ntrig: "..tostr(tresult).."\n\ndiff: "..tostr(delta),-63,-63,13) end __gfx__ diff --git a/profiling.p8 b/profiling.p8 index 5d5bd6e..9c33151 100644 --- a/profiling.p8 +++ b/profiling.p8 @@ -352,6 +352,11 @@ end,function(dx, dy) if (d