Re: Complex square root of -1 : zsqrt(-1)

Liste des GroupesRevenir à cl forth 
Sujet : Re: Complex square root of -1 : zsqrt(-1)
De : krishna.myneni (at) *nospam* ccreweb.org (Krishna Myneni)
Groupes : comp.lang.forth
Date : 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

Date Sujet#  Auteur
25 Aug 24 * Complex square root of -1 : zsqrt(-1)22ahmed
25 Aug 24 +- Re: Complex square root of -1 : zsqrt(-1)1Ron AARON
25 Aug 24 +- Re: Complex square root of -1 : zsqrt(-1)1minforth
25 Aug 24 +* Re: Complex square root of -1 : zsqrt(-1)17Anton Ertl
25 Aug 24 i`* Re: Complex square root of -1 : zsqrt(-1)16ahmed
25 Aug 24 i +- Re: Complex square root of -1 : zsqrt(-1)1Krishna Myneni
28 Aug 24 i `* Re: Complex square root of -1 : zsqrt(-1)14Anton Ertl
28 Aug 24 i  `* Re: Complex square root of -1 : zsqrt(-1)13ahmed
28 Aug 24 i   `* Re: Complex square root of -1 : zsqrt(-1)12ahmed
28 Aug 24 i    `* Re: Complex square root of -1 : zsqrt(-1)11mhx
28 Aug 24 i     `* Re: Complex square root of -1 : zsqrt(-1)10ahmed
28 Aug 24 i      `* Re: Complex square root of -1 : zsqrt(-1)9ahmed
28 Aug 24 i       +* Re: Complex square root of -1 : zsqrt(-1)7mhx
28 Aug 24 i       i`* Re: Complex square root of -1 : zsqrt(-1)6ahmed
28 Aug 24 i       i +- Re: Complex square root of -1 : zsqrt(-1)1ahmed
29 Aug 24 i       i `* Re: Complex square root of -1 : zsqrt(-1)4mhx
6 Sep 24 i       i  `* Re: Complex square root of -1 : zsqrt(-1)3ahmed
6 Sep 24 i       i   `* Re: Complex square root of -1 : zsqrt(-1)2minforth
6 Sep 24 i       i    `- Re: Complex square root of -1 : zsqrt(-1)1minforth
28 Aug 24 i       `- Re: Complex square root of -1 : zsqrt(-1)1ahmed
25 Aug 24 `* Re: Complex square root of -1 : zsqrt(-1)2Krishna Myneni
25 Aug 24  `- Re: Complex square root of -1 : zsqrt(-1)1Krishna Myneni

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal