• Re: Circumference of an ellipse

    From none) (albert@21:1/5 to the.beez.speaks@gmail.com on Fri Sep 22 15:53:25 2023
    In article <930c944c-c7d4-4ad6-9c4c-cb4e07604b30n@googlegroups.com>,
    Hans Bezemer <the.beez.speaks@gmail.com> wrote:
    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.

    What?
    \ --------------------------------
    WANT -fp- MARK-TIME
    FINIT

    : test 1.0E100 1,000,000 0 DO FSQRT 1.0E0 F+ LOOP ;

    MARK-TIME test FS. ELAPSED .uS
    \ --------------------------------

    INCLUDE /tmp/fp.frt
    test : ISN'T UNIQUE
    2.618033988749894687E0 26701 uS OK
    27 ns for a FSQRT with an increment thrown in.
    Even with a 1 KWatt machine an .25 per KWh that is
    astronomically inexpensive.


    Hans Bezemer
    --
    Don't praise the day before the evening. One swallow doesn't make spring.
    You must not say "hey" before you have crossed the bridge. Don't sell the
    hide of the bear until you shot it. Better one bird in the hand than ten in
    the air. First gain is a cat spinning. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to All on Fri Sep 22 06:28:41 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to none albert on Fri Sep 22 07:52:08 2023
    On Friday, September 22, 2023 at 3:53:29 PM UTC+2, none albert wrote:
    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.
    What?
    If you leech a CPU instruction - sure. If you do it in high level Forth, it's more expensive.
    That goes for everything a CISC processor delivers.

    Hans Bezemer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to Hans Bezemer on Fri Sep 22 11:31:35 2023
    On Friday, September 22, 2023 at 4:52:10 PM UTC+2, Hans Bezemer wrote:
    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.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to Marcel Hendrix on Fri Sep 22 12:21:01 2023
    On Friday, September 22, 2023 at 8:31:37 PM UTC+2, Marcel Hendrix wrote:
    On Friday, September 22, 2023 at 4:52:10 PM UTC+2, Hans Bezemer wrote:
    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.
    I never claimed the fast one is very accurate. I just claimed it was more accurate
    than the usual 2Pi*(sqrt((a*a+b*b)/2)) ALLEGEDLY.

    Some people really have a problem reading a post properly.. sigh.

    Hans Bezemer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@21:1/5 to Hans Bezemer on Fri Sep 22 16:29:44 2023
    Hans Bezemer schrieb am Freitag, 22. September 2023 um 16:52:10 UTC+2:
    On Friday, September 22, 2023 at 3:53:29 PM UTC+2, none albert wrote:
    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.
    What?
    If you leech a CPU instruction - sure. If you do it in high level Forth, it's more expensive.
    That goes for everything a CISC processor delivers.

    BTW high level C offers the hypot library function. It should be efficient enough.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to minforth on Sun Sep 24 05:50:52 2023
    On Saturday, September 23, 2023 at 1:29:46 AM UTC+2, minforth wrote:
    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.

    Hans Bezemer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)