Just some quick doodles concerning this subject:
: fperi-ellipse ( a b -- peri)
fover fover f+ frot frot f- \ (a+b) (a-b)
fdup f* fover fdup f* \ (a+b) (a-b)^2 (a+b)^2
f/ 3 s>f f* \ (a+b) 3h
4 s>f fover f- fsqrt \ (a+b) 3h sqrt(4-3h)
10 s>f f+ f/ \ (a+b) (3h/(10+sqrt(4-3h)))
1 s>f f+ f* pi f* \ pi*(a+b)*(1+(3h/(10+sqrt(4-3h))))
;
( a b -- peri)
: fperi-ellipse-fast 75 s>f f* fswap 120 s>f f* f+ 100 s>f f/ pi f* ;
The first is of Ramanujan - with excellent accuracy. The second has allegedly >better properties than the more familiar 2PI (SQRT((a*a+b*b)/2)) and doesn't >need an expensive FSQRT.
Hans Bezemer--
If you leech a CPU instruction - sure. If you do it in high level Forth, it's more expensive.The first is of Ramanujan - with excellent accuracy. The second has allegedlyWhat?
better properties than the more familiar 2PI (SQRT((a*a+b*b)/2)) and doesn't
need an expensive FSQRT.
On Friday, September 22, 2023 at 3:53:29 PM UTC+2, none albert wrote:[..]
On Friday, September 22, 2023 at 4:52:10 PM UTC+2, Hans Bezemer wrote:I never claimed the fast one is very accurate. I just claimed it was more accurate
On Friday, September 22, 2023 at 3:53:29 PM UTC+2, none albert wrote:[..]
A single fsqrt is 6.308 ns, a single fperi-ellipse 15.3 ns, and fperi-ellipse-fast is 6.07 ns.
1. fsqrt is so fast that we can't test it with a simple DO ... LOOP.
2. fsqrt's properties are no excuse for the horribly inaccurate fperi-ellipse-fast.
On Friday, September 22, 2023 at 3:53:29 PM UTC+2, none albert wrote:
If you leech a CPU instruction - sure. If you do it in high level Forth, it's more expensive.The first is of Ramanujan - with excellent accuracy. The second has allegedlyWhat?
better properties than the more familiar 2PI (SQRT((a*a+b*b)/2)) and doesn't
need an expensive FSQRT.
That goes for everything a CISC processor delivers.
BTW high level C offers the hypot library function. It should be efficient enough.If you mean by efficient "faster" - are you very sure about that? I have my doubts.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 52:09:58 |
Calls: | 6,712 |
Calls today: | 5 |
Files: | 12,243 |
Messages: | 5,355,173 |
Posted today: | 1 |