Sujet : Re: Complex square root of -1 : zsqrt(-1)
De : krishna.myneni (at) *nospam* ccreweb.org (Krishna Myneni)
Groupes : comp.lang.forthDate : 25. Aug 2024, 20:08:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vafvf7$22351$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 8/25/24 03:34, 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?
NB.
-1e 1e-16 zsqrt z. 0.0000000000000000612303176911189+1.i ok
-1e 1e-100 zsqrt z. 0.0000000000000000612303176911189+1.i ok
Last time I checked, Gforth did not supply the complex number arithmetic library provided in the Forth Scientific Library -- maybe a copyright issue? This library was developed by David N. Williams, and has significant amount of automated test code -- see complex-test.4th in the kForth distribution.
Under kForth, the FSL complex library of DNW gives the following for your test cases (note Z** is Z^ in the FSL complex library):
-1e 0e 0.5e 0e z^ z.
6.12303e-17 + i1 ok \ correct to within fp double precision
-1e 0e zsqrt z.
0 + i1 ok \ correct
0e 0e 1e 0e z^ z.
nan + inan ok \ incorrect
0e 0e 1e 0e z^ z.
nan + inan ok \ incorrect
The FSL complex library's ZSQRT handles the cases above correctly, but Z^ does not handle the corner cases for powers of Z=0 correctly. Examining the test code, I find that there are no tests for powers of Z=0 in complex-test.4th.
0.1414213562373095048802E1 FCONSTANT rt2
t{ 1+i0 0+i0 z^ -> 1+i0 z}t
t{ -1+i0 0+i0 z^ -> 1+i0 z}t
t{ 0+i1 0+i0 z^ -> 1+i0 z}t
t{ 0-i1 0+i0 z^ -> 1+i0 z}t
t{ rt2 rt2 0+i0 z^ -> 1+i0 z}t
t{ rt2 -rt2 0+i0 z^ -> 1+i0 z}t
t{ -rt2 rt2 0+i0 z^ -> 1+i0 z}t
t{ -rt2 -rt2 0+i0 z^ -> 1+i0 z}t
-- Krishna