Sujet : Re: Complex square root of -1 : zsqrt(-1)
De : minforth (at) *nospam* gmx.net (minforth)
Groupes : comp.lang.forthDate : 25. Aug 2024, 17:50:33
Autres entêtes
Organisation : novaBBS
Message-ID : <726273940b8c4d22a3b42f85c11fb02c@www.novabbs.com>
References : 1
User-Agent : Rocksolid Light
On Sun, 25 Aug 2024 8:34:02 +0000, ahmed wrote:
Hi,
With gforth, complex.fs included.
>
When calculating the square root of -1, I find that:
-1e 0e 0.5e 0e z** z. 0.0000000000000000612303176911189+1.i ok
-1e 0e zsqrt z. NaN ok
>
>
What's the problem with zsqrt?
Of course you know that fp operations are nearly always just
approximations.
IOW you could improve gforth's original definition to suit your
needs:
: zsqrt ( z -- sqrt[z] )
zdup z0= 0= IF
fdup f0= IF fdrop fsqrt 0e EXIT THEN
zln z2/ zexp THEN ;