From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,47fc49812a5e8e38 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: small example, using complex variables in Ada Date: Wed, 09 Jun 2010 15:43:56 +0300 Organization: Tidorum Ltd Message-ID: <879gkdFr6sU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net LQhfCdkyipdf2G7A6oneQA9eAbU04fZchi7fhGOmDJgWDZrlDB Cancel-Lock: sha1:yz+iPy2LqUg7HAGI3umO2vPHzYM= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: Xref: g2news2.google.com comp.lang.ada:12479 Date: 2010-06-09T15:43:56+03:00 List-Id: Nasser M. Abbasi wrote [much snipped]: > I wrote a simple program, to find the DFT of > an array of 3 elements {1,2,3} (DFT=discrete Fourier transform). > I also wrote a FORTRAN equivalent of the small Ada function. Here is > below the Ada code, and the FORTRAN code. > > ====== START ADA ============ > X(k) := X(k) + data(m) * exp(- J*(2.0*Pi)/float(N) * > float(m*k) ); > ======= FORTRAN code =========== > X(k) = X(k) + data(m) * EXP(-1.0*J*2.0*Pi/N *(m-1)*(k-1) ) There is an obscure difference in these computations, which can cause trouble when the data vector is much longer than the N = 3 in the example. The Ada version may then fail because the product m*k may overflow the Integer range. It would be safer to write float(m)*float(k). In the Fortran version, as far as I understand the Fortran rules, the compiler may choose to multiply the integer subexpressions (m-1) and (k-1) as integers, and then convert the product to REAL (as is done in Nasser's Ada version), or the compiler may choose to convert separately (m-1) to REAL and (k-1) to REAL and use REAL multiplication, as I suggest above for the Ada code. IIUC it would be safer in Fortran, too, to prevent integer overflow by explicit conversions of (m-1) and (k-1) to REAL before multiplication. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .