Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!inmos!steveh@lion.inmos.co.uk From: steveh@lion.inmos.co.uk (Steven Huggins) Newsgroups: comp.lang.fortran Subject: Re Dumb behaviour in Sun Fortran v1.3.1 Keywords: complex arithmetic Message-ID: <14423@ganymede.inmos.co.uk> Date: 21 Feb 91 11:23:44 GMT Sender: news@inmos.co.uk Reply-To: steveh@inmos.co.uk () Organization: INMOS Limited, Bristol, UK. Lines: 64 In article <1991Feb16.011005.4289@cs.olemiss.edu> randy@tacky.cs.olemiss.edu (Randy Zagar) writes: >Sun's F77 v1.3.1 evaluates expressions involving complex numbers inefficiently. >The offending expressions are of the type > > (complex expression) / (real expression) > >which are converted to > > (complex expression) / (complex expression) > >and then evaluated by complex division. The expression should be evaluated a > > (complex expression) * (1.0 / real expression) > >which only involves a real division and a real multiply. Well, although this may increase speed on the Sun, it may also decrease the accuracy of the answer because two roundings are made rather than one ( for both real and imaginary parts ). The reasoning is as follows: a + ib ac + bd bc - ad -------- = ----------- + i ----------- c + id c**2 + d**2 c**2 + d**2 d d a + b( - ) b - a( - ) c c = ------------ + i ------------ , for c <> 0 d d c + d( - ) c + d( - ) c c which, if d = 0, becomes, as expected, a b = - + i - c c It is this final expression that the compiler should be evaluating - two divisions, each only rounded once. Zagar's formula would generate at least one division and two multiplications, and use double rounding. By the way, talking of complex numbers in FORTRAN, does anybody know what sort of applications would use the following: complex / complex and expecially complex ** complex Steven R Huggins, Software Development Group, INMOS Ltd., 1000 Aztec West, Almondsbury, Bristol, United Kingdom. BS12 4SQ Tel: 0454 616616 JANET: steveh@uk.co.inmos INTERNET: steveh@inmos.com Other possibility: steveh@inmos.co.uk