From: wester@ilt.fhg.de
To: caml-list@inria.fr
Subject: [Caml-list] Re: Complex Arithmetic
Date: Wed, 28 Mar 2001 10:44:05 +0200 [thread overview]
Message-ID: <200103280844.KAA29428@ilt.fhg.de> (raw)
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 <complex>
#include <iostream>
main()
{
complex<double> a,b,c,d,e,f;
a = complex<double>(0.0,-1.0);
b = complex<double>(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
next reply other threads:[~2001-03-28 8:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-28 8:44 wester [this message]
2001-03-28 9:20 ` David McClain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200103280844.KAA29428@ilt.fhg.de \
--to=wester@ilt.fhg.de \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox