Sujet : Re: Complex square root of -1 : zsqrt(-1)
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forthDate : 28. Aug 2024, 20:38:09
Autres entêtes
Organisation : novaBBS
Message-ID : <a886e3f176a33b9a041d8b36fea3916e@www.novabbs.com>
References : 1 2 3 4 5 6 7
User-Agent : Rocksolid Light
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