This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fwd: Re: Problem with GNAT Ada floating-point image representationunder HPUX]



-------- Original Message --------
Subject: Re: Problem with GNAT Ada floating-point image representation
under HPUX
Date: Sun, 23 Oct 2005 10:43:12 +0200
From: .:SB:. <stigmatedbrain@gmail.com>
To: Clarke, Carus V <carus.v.clarke@pss.Boeing.com>
References:
<0EB5A85C41870F46B6F9B2283CCCEB80022183A4@XCH-NW-2V2.nw.nos.boeing.com>

Good reading is "Programming in ADA 95 2nd Ed, John Barnes" Addison-Wesley.

It's not a question about the compiler, floating point variables are
always hardware dependent, this is why it's recommended to create an own
float package customized to your needs. And at the same time, you have
the text representation of the float in Float_IO Package.

Pag 40, Genericity
"The standard package for the input and output of floating point values
in text from is GENERIC with respect to the actual floating point type.
This is because it is needed a single package to cope with all the
possible floating types such as the underlying machine types Float and
Long_Float as well as the portable type My_Float"

Pag 596, Finale - Portability
"There is, however, one simple rule which should be followed. We should
always declare our own floating point types and not directly use the
predefined types such as Float."

Take a look to Float_IO package and you will realize it, check also
"Floating point types" pg 341.

Good luck,

Float are allways "interesting" when you are pressed by the boss :)

I'll allways have fear about planes... sorry :)

J.J.


Clarke, Carus V wrote:
> I have been using the gcc 3.4.4 GNAT compiler to compile an existing Ada
> program on an HP-UX 11 system. 
> 
> We have noticed that generated images of floating-point numbers often
> appear with the least-significant digit incremented by 1.  Since the
> application is used in a calibration laboratory, this situation is not
> acceptable to the users.  Below is some sample output, followed by a
> listing of the program that produced the output.  This same program
> produces the expected output when compiled and run on a Windows machine,
> that uses the same revision (3.4.4 -- cygming special) of the compiler.
> The program also produces the expected output when compiled with the
> older GNAT-3.15p compiler on the HP-UX machine.  Using gdb 6.3 to step
> through the program as it was running on the HP-UX machine showed that
> the Value attribute did correctly convert the string representation
> ("1.0000") to 1.0 for both Float and Long_Float cases.
> 
> The build configuration for the compiler is:
> 
> Reading specs from
> /site/sw/gcc-3.4.4/lib/gcc/hppa2.0w-hp-hpux11.11/3.4.4/specs
> Configured with: ../gcc-3.4.4/configure --prefix=/site/sw/gcc-3.4.4
> --with-gnu-as --with-as=/site/sw/gcc-3.4.4/bin/as --disable-nls
> --enable-languages=c,c++,ada --enable-threads=gnat
> Thread model: gnat
> gcc version 3.4.4
> 
> And the as version is:
> 
> GNU assembler version 2.15 (hppa2.0w-hp-hpux11.11) using BFD version
> 2.15
> 
> I have also noted the same behavior with the gcc 4.0 GNAT compiler.
> 
> Any suggestions or ideas would be appreciated.
> 
> Thanks,
> 
> Carus V. (Bud) Clarke
> carus.v.clarke@boeing.com
> 
> ------------------------------------------------------------------------
> ------------------
> 
> Program output:
> 
> The number's string representation is: 1.0000
> The image of the float value is:  1.00001E+00
> Text_Io output for float value is:    1.00001
> The image of the long-float value is:  1.00000000000001E+00
> Text_Io output for long-float value is:    1.0000001
> 
> ------------------------------------------------------------------------
> ------------------
> 
> Program code:
> 
> ------------------------------------------------------------------------
> -- File: test_float_image.adb
> -- Date: Oct. 20, 2005
> ------------------------------------------------------------------------
> 
> with Ada.Text_Io;
> with Ada.Float_Text_Io;
> with Ada.Long_Float_Text_Io;
> 
> procedure Test_Float_Image is
>    XSTR : constant String     := "1.0000";
>    XF   : constant Float      := Float'Value(XSTR);
>    XL   : constant Long_Float := Long_Float'Value(XSTR);
> begin
>    Ada.Text_Io.Put ("The number's string representation is: ");
>    Ada.Text_Io.Put (XSTR);
>    Ada.Text_Io.New_Line;
>    Ada.Text_Io.Put ("The image of the float value is: ");
>    Ada.Text_Io.Put (Float'Image(XF));
>    Ada.Text_Io.New_Line;
>    Ada.Text_Io.Put ("Text_Io output for float value is: ");
>    Ada.Float_Text_Io.Put (Item => XF,
>                                      Fore => 4,
>                                      Aft  => 5,
>                                      Exp  => 0);
>    Ada.Text_Io.New_Line;
>    Ada.Text_Io.Put ("The image of the long-float value is: ");
>    Ada.Text_Io.Put (Long_Float'Image(XL));
>    Ada.Text_Io.New_Line;
>    Ada.Text_Io.Put ("Text_Io output for long-float value is: ");
>    Ada.Long_Float_Text_Io.Put (Item => XL,
>                                               Fore => 4,
>                                               Aft  => 7,
>                                              Exp  => 0);
>    Ada.Text_Io.New_Line;
> end Test_Float_Image;
> 
> ------------------------------------------------------------------------
> ------------------
> 
> 

-- 
Linux goliathbox.stigmatedbrain.net 2.6.12 i686 GNU/Linux
10:25:01 up 3 days, 14:09, 29 users, load average: 0.08, 0.46, 1.22
---------------------------------------------------------
Experience is a good teacher, but she sends in terrific bills. -- Minna
Antrim, "Naked Truth and Veiled Allusions"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]