From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA26317; Wed, 28 Mar 2001 10:44:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA26313 for ; Wed, 28 Mar 2001 10:44:09 +0200 (MET DST) Received: from mailgw1.fhg.de (mailgw1.fhg.de [153.96.1.2]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f2S8i9P23212 for ; Wed, 28 Mar 2001 10:44:09 +0200 (MET DST) Received: from ilt.fhg.de (ilt.ilt.fhg.de [153.96.180.2]) by mailgw1.fhg.de (8.11.1/8.11.1) with ESMTP id f2S8i6h19683 for ; Wed, 28 Mar 2001 10:44:06 +0200 (MET DST) Received: from eent230 (iltpc099.ilt.fhg.de [192.102.148.99]) by ilt.fhg.de (8.9.3/8.9.3) with SMTP id KAA29428 for ; Wed, 28 Mar 2001 10:44:08 +0200 (MET DST) Message-Id: <200103280844.KAA29428@ilt.fhg.de> From: wester@ilt.fhg.de To: caml-list@inria.fr Date: Wed, 28 Mar 2001 10:44:05 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: [Caml-list] Re: Complex Arithmetic X-mailer: Pegasus Mail for Win32 (v3.01d) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi David, as far as I understood Kahan says that the complex arithmetic in FORTRAN and many C++ libraries is wrong. I tested: sqrt( (0.0 , -1.0)**2 ) vs. sqrt( (0.0 , 1.0)**2 ) on a DEC Alpha with FORTRAN and C++ (source and output below). They both give the correct result. A naive approach abviously gives the same result (0.0, 1.0) for both expressions. Can you tell us how you implemented the correct behaviour in OCaml (or Nml)? BTW what about sqrt( (-1.0 , -1.0)**2 ) and sqrt( (-1.0 , 1.0)**2 ), which result in (1.0, 1.0) and (1.0, -1.0) on the DEC Alpha. What should the results be in this case? Rolf // c++ on DEC Alpha #include #include main() { complex a,b,c,d,e,f; a = complex(0.0,-1.0); b = complex(0.0, 1.0); c = a*a; d = b*b; e = sqrt(c); f = sqrt(d); cout << a << " , " << b << endl; cout << c << " , " << d << endl; cout << e << " , " << f << endl; } Output: (0,-1) , (0,1) (-1,-0) , (-1,0) (6.12323e-17,-1) , (6.12323e-17,1) //f77 on DEC Alpha complex*16 a,b,c,d,e,f a = (0.0,-1.0) b = (0.0, 1.0) c = a**2 d = b**2 e = sqrt(c) f = sqrt(d) write(6,*) a,b write(6,*) c,d write(6,*) e,f stop end Output: (0.000000000000000E+000,-1.00000000000000) (0.000000000000000E+000,1.00000000000000) (-1.00000000000000,0.000000000000000E+000) (-1.00000000000000,0.000000000000000E+000) (0.000000000000000E+000,-1.00000000000000) (0.000000000000000E+000,1.00000000000000) ------------------------------------- Rolf Wester wester@ilt.fhg.de ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr