comp.lang.ada
 help / color / mirror / Atom feed
* Long Float Error from Gnat
@ 1998-10-29  0:00 Al Christians
  1998-10-30  0:00 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Al Christians @ 1998-10-29  0:00 UTC (permalink / raw)


I've hit an odd numerical error in a program that I've compiled
with GNAT 3.10p1 on NT 4 sp3.  I almost can't believe it, so I wonder 
if anyone else can tell me what's going on.  My number one suspect is 
that it's a floating point problem in my Pentium Pro.

Here's the code:
-------------------------------------------------------------------

with Ada.Text_Io;
with Ada.Long_Float_Text_Io;
with Ada.Integer_Text_IO;
procedure Num_Test is

   procedure Read_Num( S:  String ) is
      Num:            Long_Float;
      Last_Char_Pos:      Positive;
   begin
      Ada.Long_Float_Text_Io.Get( S, Num, Last_Char_Pos );
      Ada.Text_Io.Put( "Success: " &  S  & " = " );
      Ada.Long_Float_Text_Io.Put( Num );
      Ada.Text_Io.Put( "  Last Char Pos: " &  " = " );
      Ada.Integer_Text_Io.Put( Last_Char_Pos );
      Ada.Text_Io.New_Line;
   exception
      when others =>
         Ada.Text_Io.Put( "Error: " &  S  );
         Ada.Text_Io.New_Line;
   end;

begin
   Read_Num(  "1.0" );
   Read_Num(  "1.23456789" );
   Read_Num(  "1.2345678901234" );
   Read_Num(  "1.234567890E+1" );
   Read_Num( "-1.234567890E+1" );
   Read_Num(  "1.234567890E+39" );
   Read_Num( "-1.234567890E-39" );
   Read_Num( "-1.000000000E-32" );
   Read_Num(  "1.000000000E-32" );
   Read_Num( "-5.000000000E-32" );
   Read_Num(  "5.000000000E-32" );
   Read_Num( "-5.0000000000E-32" );
   Read_Num(  "5.0000000000E-32" );
   Read_Num( "-5.00000000E-32" );
   Read_Num(  "5.00000000E-32" );
   Read_Num( "-50.00000000E-33" );
   Read_Num(  "50.00000000E-33" );
   Read_Num( "-1.200000000E-32" );
   Read_Num(  "1.200000000E-32" );
   Read_Num( "-1.270000000E-32" );
   Read_Num(  "1.270000000E-32" );
   Read_Num( "-1.271110000E-32" );
   Read_Num(  "1.271110000E-32" );
   Read_Num( "-1.271113762E-32" );
   Read_Num(  "1.271113762E-32" );
   Read_Num(  "1.271113763E-32" );
   Read_Num( "-1.271113763E-32" );
   Read_Num( "-1.271113764E-32" );
   Read_Num(  "1.271113764E-32" );
   Read_Num(  "1.271113763E-33" );
   Read_Num( "-1.271113763E-33" );
   Read_Num(  "1.2711137638E-33" );
   Read_Num( "-1.2711137638E-33" );
   Read_Num(  "1.271113763E-30" );
   Read_Num( "-1.271113763E-30" );
   Read_Num(  "1.2E-32" );
   Read_Num( "-1.2E-32" );
end Num_Test;

-------------------------------End of Code -------------------------

Here's the output

--------------------------------------------------------------------

Success: 1.0 =  1.00000000000000E+00  Last Char Pos:  =           3
Success: 1.23456789 =  1.23456789000000E+00  Last Char Pos:  =         
10
Success: 1.2345678901234 =  1.23456789012340E+00  Last Char Pos: 
=          15
Success: 1.234567890E+1 =  1.23456789000000E+01  Last Char Pos: 
=          14
Success: -1.234567890E+1 = -1.23456789000000E+01  Last Char Pos: 
=          15
Success: 1.234567890E+39 =  1.23456789000000E+39  Last Char Pos: 
=          15
Success: -1.234567890E-39 = -1.23456789000000E-39  Last Char Pos: 
=          16
Success: -1.000000000E-32 = NaN******************  Last Char Pos: 
=          16
Success: 1.000000000E-32 = NaN******************  Last Char Pos: 
=          15
Success: -5.000000000E-32 = NaN******************  Last Char Pos: 
=          16
Success: 5.000000000E-32 = NaN******************  Last Char Pos: 
=          15
Success: -5.0000000000E-32 = -5.00000000000000E-32  Last Char Pos: 
=          17
Success: 5.0000000000E-32 =  5.00000000000000E-32  Last Char Pos: 
=          16
Success: -5.00000000E-32 = -5.00000000000000E-32  Last Char Pos: 
=          15
Success: 5.00000000E-32 =  5.00000000000000E-32  Last Char Pos: 
=          14
Success: -50.00000000E-33 = NaN******************  Last Char Pos: 
=          16
Success: 50.00000000E-33 = NaN******************  Last Char Pos: 
=          15
Success: -1.200000000E-32 = NaN******************  Last Char Pos: 
=          16
Success: 1.200000000E-32 = NaN******************  Last Char Pos: 
=          15
Success: -1.270000000E-32 = NaN******************  Last Char Pos: 
=          16
Success: 1.270000000E-32 = NaN******************  Last Char Pos: 
=          15
Success: -1.271110000E-32 = NaN******************  Last Char Pos: 
=          16
Success: 1.271110000E-32 = NaN******************  Last Char Pos: 
=          15
Success: -1.271113762E-32 = NaN******************  Last Char Pos: 
=          16
Success: 1.271113762E-32 = NaN******************  Last Char Pos: 
=          15
Success: 1.271113763E-32 = NaN******************  Last Char Pos: 
=          15
Success: -1.271113763E-32 = NaN******************  Last Char Pos: 
=          16
Success: -1.271113764E-32 = NaN******************  Last Char Pos: 
=          16
Success: 1.271113764E-32 = NaN******************  Last Char Pos: 
=          15
Success: 1.271113763E-33 =  1.27111376300000E-33  Last Char Pos: 
=          15
Success: -1.271113763E-33 = -1.27111376300000E-33  Last Char Pos: 
=          16
Success: 1.2711137638E-33 =  1.27111376380000E-33  Last Char Pos: 
=          16
Success: -1.2711137638E-33 = -1.27111376380000E-33  Last Char Pos: 
=          17
Success: 1.271113763E-30 =  1.27111376300000E-30  Last Char Pos: 
=          15
Success: -1.271113763E-30 = -1.27111376300000E-30  Last Char Pos: 
=          16
Success: 1.2E-32 =  1.20000000000000E-32  Last Char Pos:  =           7
Success: -1.2E-32 = -1.20000000000000E-32  Last Char Pos:  =           8

------------------------------End of Output ---------------------------

Question relates to the surprising incidence of NaN's in the output.
These all look like properly formatted strings.  It looks as if any
number with exponent E-32 and exactly 10 digits -> NaN. How could this
be?

TIA for any help.


Al




^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~1998-11-03  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-29  0:00 Long Float Error from Gnat Al Christians
1998-10-30  0:00 ` Stephen Leake
1998-10-30  0:00   ` Al Christians
1998-10-31  0:00     ` dewar
1998-10-31  0:00       ` Al Christians
1998-11-01  0:00         ` dewarr
1998-11-01  0:00           ` Al Christians
1998-11-01  0:00             ` bob
1998-11-02  0:00               ` Bargin GNAT support prices (Was Re: Long Float Error from Gnat) taashlo
1998-11-03  0:00                 ` dewar
1998-11-02  0:00             ` Long Float Error from Gnat dewar
1998-11-02  0:00               ` dennison
1998-10-30  0:00 ` jrcarter001
1998-10-30  0:00   ` Al Christians
1998-10-30  0:00 ` Jerry van Dijk

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