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,8c0fcfc0a87e61fc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!feeder.erje.net!news.mixmin.net!aioe.org!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: simple question on long_float/short_float Date: Sat, 02 Oct 2010 02:11:10 -0700 Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: nma@12000.org NNTP-Posting-Host: tUYQ4Ty9mMw9Pdc8TJRFQA.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.12) Gecko/20100914 Thunderbird/3.0.8 Xref: g2news1.google.com comp.lang.ada:14350 Date: 2010-10-02T02:11:10-07:00 List-Id: Ada experts; I have a follow up. It says here http://www.pegasoft.ca/resources/boblap/17.html "Gnat provides interfacing packages for languages besides C. Interfaces.Fortran contains types and subprograms to link Fortran language programs to your Ada programs. The GCC Fortran 77 compiler is g77. As with gcc, most of the Fortran data types correspond identically with an Ada type. A Fortran real variable, for example, is the same as an Ada float, and a double precision variable is an Ada long_float. Other Ada compilers may not do this: if portability is an issue, always use the types of Interfaces.Fortran." I wrote a small Ada program to print a value of a floating number which has the type Double_Precision, and printed the value to the screen. I did the same in Fortran, same number, and printed the value to screen. In Fortran, the value printed is that of IEEE754, and in Ada it also printed the same as Fortran. So I am happy to see that. Here is the code and the output: ---- Ada v1 ---- with ada.text_io; with Interfaces.Fortran; use Interfaces.Fortran; procedure test is package my_float_IO is new Ada.Text_IO.float_IO(Double_Precision); use my_float_IO; a : Double_Precision := 2.3; begin Put( item=>a,Fore=>25,Aft=>16) ; end test; ---- fortran ---- program main implicit none double precision :: c=2.3D0 write (*,'(F25.16)') c end program main ---- output of the above in same order ---- 2.2999999999999998E+00 ---- Ada 2.2999999999999998 ---- Fortran Then I changed the Ada code to the following: ---- Ada v2 ----- with ada.text_io; procedure test is type my_float_type is digits 16; package my_float_IO is new Ada.Text_IO.float_IO(my_float_type); use my_float_IO; a : my_float_type := 2.3; begin Put( item=>a,Fore=>25,Aft=>16) ; end test; and now the output is 2.3000000000000000E+00 ------------------------------ 1) So, it seems to me that Ada did use Fortran double in v1. since output is different than in v2. Unless I made a mistake in v2. Hence, I do not understand why the webpage above said that Gnat would use the same types. Can I change v2 to make it output the same as Fortran? I assume not, since it is not double to start with. 2) The reason I wanted to use Fortran double type, so I can compare the output of my Ada program to that of Fortran and some output in the textbook. 3) I need to read more about Ada Float type. Standard is IEEE754, so if Ada float does not use this, would this not make the analysis of floating point computation in Ada harder? Most textbooks and numerical stuff, assume IEEE754 computation done on floating points. I also need to study more about Ada floats and how they work. What I do not understand yet, does Ada does use IEEE754 for its floats? Assuming it does, then it must do something additional at run-time to obtain the result it needs when one uses DIGITS nnn in the type definition for Ada float. --Nasser