comp.lang.ada
 help / color / mirror / Atom feed
From: "cjpsimon@gmail.com" <cjpsimon@gmail.com>
Subject: Re: simple question on long_float/short_float
Date: Sat, 2 Oct 2010 03:45:33 -0700 (PDT)
Date: 2010-10-02T03:45:33-07:00	[thread overview]
Message-ID: <b445898f-6868-45d5-85e8-59c92131153e@28g2000yqm.googlegroups.com> (raw)
In-Reply-To: i86svu$6ki$1@speranza.aioe.org

On 2 oct, 11:11, "Nasser M. Abbasi" <n...@12000.org> wrote:
> Ada experts;
>
> I have a follow up.
>
> It says herehttp://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

I think Long_Float representation is limited to digits 15. As you want
to
have digits 16 the compiler have to choose Long_Long_Float
representation
or to reject your code depending of the hardware.

Claude



  parent reply	other threads:[~2010-10-02 10:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-30  6:17 simple question on long_float/short_float Nasser M. Abbasi
2010-09-30  6:58 ` J-P. Rosen
2010-09-30  8:31   ` Nasser M. Abbasi
2010-09-30  8:45     ` Nasser M. Abbasi
2010-09-30  9:59       ` Mark Lorenzen
2010-09-30 13:30       ` Peter C. Chapin
2010-09-30  8:46     ` AdaMagica
2010-09-30 10:02     ` Georg Bauhaus
2010-09-30 15:37     ` Jeffrey Carter
2010-09-30 18:22       ` Nasser M. Abbasi
2010-09-30 21:21       ` Peter C. Chapin
2010-10-01  0:29         ` Nasser M. Abbasi
2010-10-01 11:13           ` Peter C. Chapin
2010-10-02 19:57         ` Simon Wright
2010-09-30 15:56     ` Adam Beneschan
2010-10-02  9:11 ` Nasser M. Abbasi
2010-10-02  9:48   ` Dmitry A. Kazakov
2010-10-02 20:09     ` Simon Wright
2010-10-02  9:56   ` Nasser M. Abbasi
2010-10-02 10:45   ` cjpsimon [this message]
2010-10-02 16:52   ` Jeffrey Carter
2010-10-02 20:01     ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox