Re: Complex square root of -1 : zsqrt(-1)

Liste des GroupesRevenir à cl forth 
Sujet : Re: Complex square root of -1 : zsqrt(-1)
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forth
Date : 28. Aug 2024, 23:10:46
Autres entêtes
Organisation : novaBBS
Message-ID : <db254672d6f9222e538709f19433c6d0@www.novabbs.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Rocksolid Light
On Wed, 28 Aug 2024 21:42:15 +0000, mhx wrote:

How about
: xpythag ( F: a b -- c ) \ compute sqrt(a^2+b^2) without overflow
FABS FSWAP FABS FSWAP
F2DUP F> IF  FOVER ( F: a b a -- ) F/ FSQR F1+ FSQRT  F*  EXIT  ENDIF
FDUP F0= IF  0e
       ELSE  FTUCK ( F: b a b -- ) F/ FSQR F1+ FSQRT  F*
      ENDIF ;
>
FORTH> 1e-309 0e xpythag +e.  1.0000000000000000000e-0309 ok
FORTH> 1e-319 0e xpythag +e.  9.9999999999999999992e-0320 ok
>
-marcel
In my defintion of |z| I forgot to process the case where a=0 or b=0.
Yes, your definition captures my approach (idea).
It works but for 0e 0e xpythag gives 0e and the fstack is not consumed.
We must empty the fstack in this case.
the defintion becomes
: xpythag ( F: a b -- c ) \ compute sqrt(a^2+b^2) without overflow
FABS FSWAP FABS FSWAP
F2DUP F> IF  FOVER ( F: a b a -- ) F/ FSQR F1+ FSQRT  F*  EXIT  ENDIF
FDUP F0= IF  fdrop fdrop 0e
       ELSE  FTUCK ( F: b a b -- ) F/ FSQR F1+ FSQRT  F*
      ENDIF ;
and for z** we can use this defintion of xpythag for |z|
Ahmed

Date Sujet#  Auteur
25 Aug 24 * Complex square root of -1 : zsqrt(-1)22ahmed
25 Aug 24 +- Re: Complex square root of -1 : zsqrt(-1)1Ron AARON
25 Aug 24 +- Re: Complex square root of -1 : zsqrt(-1)1minforth
25 Aug 24 +* Re: Complex square root of -1 : zsqrt(-1)17Anton Ertl
25 Aug 24 i`* Re: Complex square root of -1 : zsqrt(-1)16ahmed
25 Aug 24 i +- Re: Complex square root of -1 : zsqrt(-1)1Krishna Myneni
28 Aug 24 i `* Re: Complex square root of -1 : zsqrt(-1)14Anton Ertl
28 Aug 24 i  `* Re: Complex square root of -1 : zsqrt(-1)13ahmed
28 Aug 24 i   `* Re: Complex square root of -1 : zsqrt(-1)12ahmed
28 Aug 24 i    `* Re: Complex square root of -1 : zsqrt(-1)11mhx
28 Aug 24 i     `* Re: Complex square root of -1 : zsqrt(-1)10ahmed
28 Aug 24 i      `* Re: Complex square root of -1 : zsqrt(-1)9ahmed
28 Aug 24 i       +* Re: Complex square root of -1 : zsqrt(-1)7mhx
28 Aug 24 i       i`* Re: Complex square root of -1 : zsqrt(-1)6ahmed
28 Aug 24 i       i +- Re: Complex square root of -1 : zsqrt(-1)1ahmed
29 Aug 24 i       i `* Re: Complex square root of -1 : zsqrt(-1)4mhx
6 Sep 24 i       i  `* Re: Complex square root of -1 : zsqrt(-1)3ahmed
6 Sep 24 i       i   `* Re: Complex square root of -1 : zsqrt(-1)2minforth
6 Sep 24 i       i    `- Re: Complex square root of -1 : zsqrt(-1)1minforth
28 Aug 24 i       `- Re: Complex square root of -1 : zsqrt(-1)1ahmed
25 Aug 24 `* Re: Complex square root of -1 : zsqrt(-1)2Krishna Myneni
25 Aug 24  `- Re: Complex square root of -1 : zsqrt(-1)1Krishna Myneni

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal