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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news4.google.com!proxad.net!feeder1-2.proxad.net!fdn.fr!gegeweb.org!aioe.org!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: small example, using complex variables in Ada Date: Thu, 10 Jun 2010 02:34:27 -0700 Organization: Aioe.org NNTP Server Message-ID: References: <82ljannyeq.fsf@stephe-leake.org> Reply-To: nma@12000.org NNTP-Posting-Host: c00eBs/j4mUkprxQFmXQpg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 Xref: g2news2.google.com comp.lang.ada:12541 Date: 2010-06-10T02:34:27-07:00 List-Id: On 6/10/2010 12:23 AM, Stephen Leake wrote: > >> -- gnatmake dft.adb >> -- >> -- ./dft.exe >> -- ( 6.00000E+00, 0.00000E+00) >> -- (-1.50000E+00, 8.66026E-01) >> -- (-1.50000E+00,-8.66025E-01) >> -- $ >> >> ======= FORTRAN code =========== >> ! dtf.f90, compiled with GCC 4.3.4 >> ! under CYGWIN 1.7.5 >> ! gfortran -Wall dft.f90 >> ! ./a.exe >> ! ( 6.0000000 , 0.0000000 ) >> ! ( -1.4999999 , 0.86602557 ) >> ! ( -1.5000005 ,-0.86602497 ) >> ! > > It would be good to explain the small differences here; something about > how the floating point options are set, I suspect. > Yes, I noticed that too. Need to look more into. It could be just a formating thing. I just used Print*, in Fortran becuase at the time was too lazy to lookin up the other formating functions in Fortran. In Ada, I used the predefined Put on Complex of float types. > It would be good to state the theoretically correct answer; I hope it's > 1.5, not 1.499... :). > Well, the extact answer is -1.5 for the real part of those terms. Can be seen also by using a CAS such as Mathematica which allows one to set an arbitrary precision. Here is one with 50 precision: SetPrecision[Fourier[{1., 2., 3.}, FourierParameters ->{1, -1}],50] {6.0000000000000000000000000000000000000000000000000+0.*10^-50 I, -1.5000000000000000000000000000000000000000000000000 + 0.8660254037844385965340919530941476978114224039018 I, -1.5000000000000000000000000000000000000000000000000 -0.8660254037844385965340919530941476978114224039018 I} So, it is 1.5 not 1.499999... (can also be seen by expanding the sum itself. and using Euler relation to convert exp() to trig functions and looking at the resulting cosine and sin terms, one can see this term comes out to be an exact -3/2). well look into why Fortan prints -1.499999 and correct my code if it is because I am not doing something right. --Nasser