| Deutsch English Français Italiano |
|
<db254672d6f9222e538709f19433c6d0@www.novabbs.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: melahi_ahmed@yahoo.fr (ahmed) Newsgroups: comp.lang.forth Subject: Re: Complex square root of -1 : zsqrt(-1) Date: Wed, 28 Aug 2024 22:10:46 +0000 Organization: novaBBS Message-ID: <db254672d6f9222e538709f19433c6d0@www.novabbs.com> References: <cc2a1ec5eae8d18d290b398af3c013cb@www.novabbs.com> <2024Aug25.191346@mips.complang.tuwien.ac.at> <c02b8db68bf735b5c30c7d5979b942a3@www.novabbs.com> <2024Aug28.103612@mips.complang.tuwien.ac.at> <20540ab199e43e94b3d156a1dd58e3f2@www.novabbs.com> <d9184f7688ceced53b41535c172032b3@www.novabbs.com> <f55b068b628dc4c5ae64a7d71d87c964@www.novabbs.com> <a886e3f176a33b9a041d8b36fea3916e@www.novabbs.com> <df1eb1782e95ac101f5ca81ff81f1e32@www.novabbs.com> <28fcb29094fab35007403391b3ea764e@www.novabbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: i2pn2.org; logging-data="71383"; mail-complaints-to="usenet@i2pn2.org"; posting-account="fh2jRJ/PGtIlZMySaIjc6gsLWP80WZpB2lZYFC5wgKI"; User-Agent: Rocksolid Light X-Rslight-Site: $2y$10$bC8hLPiRt2PvbFcKNtutJew4euNp8/65DxRhMM/qQHE7QFksbjKga X-Rslight-Posting-User: a55529988cdb6fa7b5e36631aef8884238b8448a X-Spam-Checker-Version: SpamAssassin 4.0.0 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