From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: small example, using complex variables in Ada
Date: Wed, 09 Jun 2010 15:43:56 +0300
Date: 2010-06-09T15:43:56+03:00 [thread overview]
Message-ID: <879gkdFr6sU1@mid.individual.net> (raw)
In-Reply-To: <hunrki$ph7$1@speranza.aioe.org>
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
. @ .
next prev parent reply other threads:[~2010-06-09 12:43 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 10:49 small example, using complex variables in Ada Nasser M. Abbasi
2010-06-09 11:26 ` Ludovic Brenta
2010-06-09 23:50 ` Jerry
2010-06-10 1:03 ` Jeffrey R. Carter
2010-06-10 15:48 ` Colin Paul Gloster
2010-06-10 14:54 ` Ludovic Brenta
2010-06-10 16:21 ` Colin Paul Gloster
2010-06-10 17:37 ` Adam Beneschan
2010-06-10 17:57 ` Jeffrey R. Carter
2010-06-10 22:32 ` Randy Brukardt
2010-06-11 12:42 ` Colin Paul Gloster
2010-06-11 18:59 ` Randy Brukardt
2010-06-14 19:19 ` Colin Paul Gloster
2010-06-14 19:48 ` Nasser M. Abbasi
2010-06-17 7:44 ` Gautier write-only
2010-06-17 10:33 ` Colin Paul Gloster
2010-06-17 14:39 ` Yannick Duchêne (Hibou57)
2010-06-17 16:36 ` Colin Paul Gloster
2010-06-09 12:43 ` Niklas Holsti [this message]
2010-06-10 7:23 ` Stephen Leake
2010-06-10 9:12 ` J-P. Rosen
2010-06-10 11:03 ` Yannick Duchêne (Hibou57)
2010-06-10 13:27 ` J-P. Rosen
2010-06-10 21:15 ` Yannick Duchêne (Hibou57)
2010-06-11 7:22 ` Dmitry A. Kazakov
2010-06-11 8:48 ` J-P. Rosen
2010-06-11 12:00 ` Brian Drummond
2010-06-10 9:34 ` Nasser M. Abbasi
2010-06-10 20:12 ` Simon Wright
2010-06-14 9:33 ` Vincent LAFAGE
2010-06-14 12:29 ` Nasser M. Abbasi
2010-06-14 13:00 ` Vincent LAFAGE
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox