Deutsch   English   Français   Italiano  
<a886e3f176a33b9a041d8b36fea3916e@www.novabbs.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!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 19:38:09 +0000
Organization: novaBBS
Message-ID: <a886e3f176a33b9a041d8b36fea3916e@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="59932"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="fh2jRJ/PGtIlZMySaIjc6gsLWP80WZpB2lZYFC5wgKI";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$mWpaOB.kECUIPsD9QHlVTOAsQSnERDliXb/fAx.cz9lsG2CVd.WAq
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Posting-User: a55529988cdb6fa7b5e36631aef8884238b8448a
Bytes: 2772
Lines: 59

On Wed, 28 Aug 2024 17:39:18 +0000, mhx wrote:

> And what does Matlab/gForth give for this?
>
> 1e-309 0e   -1e 1e  z** z. (  7.188026e+0307 -9.974133e+0308 ) ok
>
> -marcel

Yes, there is a difference between matlab and gforth for this case.
Matlab gives:
» 1e-309^(-1+i)

ans =

  7.1880e+307 -        Infi

Julia gives:
julia> 1e-309^(-1+im)
Inf - Inf*im

and gforth gives:
1e-309 0e -1e 1e z** z. NaN+NaNi  ok

I looked at complex.fs file (within gforth directory)
z** depends on zln
zln depends on >polar
>polar gives 0e for 1e-309 0e  ( 1e-309 0e >polar z. gives 0e) and that's
> a problem.
it must gives 1e-309 0e for 1e-309 0e.

>polar depends on |z| which gives 0e for 1e-309 0e ( 1e-309 0e |z| f.
> gives 0e) and that's a problem.
|z| depends on zsqabs which gives 0e for 1e-309 0e ( 1e-309 0e zsqabs f.
gives 0e ) and that's a problem

So the problem is in |z|. it must gives 1e-309 for 1e-309 0e.

I modified the definition of |z| like hereafter:

: |z| ( z: a+ib -- m) ( f: a b--m)
fover fover ( f: a b a b)
fabs fswap fabs
fmax ( f: a b mx)
frot frot ( f: mx a b)
fover fabs fover fabs fmax ( f: mx a b mx)
ftuck ( f: mx a mx b mx)
f/    ( f: mx a mx b/mx)
fdup f* frot frot ( f: mx [b/mx]^2 a mx)
f/ fdup f* f+ fsqrt f* ;

and with this definition of |z| I got:
1e-309 0e |z| fe. 1.00000000000000E-309  ok which is good.

and then for 1e-309 0e -1e 1e z** ,
gforth gives:
1e-309 0e -1e 1e z** z. inf-ini  \ inf-inf*i  ok

As you can see, it is the same result as Julia.

Ahmed