This is the mail archive of the gcc-patches@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]

[Ada] Fix error of too many digits after point in decimal output


In the case of output of values less than 0.1 where Aft was set to
0 or 1, too many digits were output after the decimal point. This
patch corrects that misbehavior. It also corrects the problem that
in this same situation if checks are on in the run-time, the call
to Round could cause an incorrect Constraint_Error exception.

Test program:

with Ada.Text_IO;
use  Ada.Text_IO;

procedure Test_Decimal_IO is

  type Decimal is delta 10.0**(-5) digits 8;

  package Test_Decimal_Text_IO is new Ada.Text_IO.Decimal_IO (Decimal);
  use Test_Decimal_Text_IO;

begin

  Put ( 0.0    , Fore =>  0, Aft =>  0, Exp => 0);  New_Line;
  Put (-0.00001, Fore =>  0, Aft =>  0, Exp => 0);  New_Line;
  Put ( 0.00011, Fore =>  0, Aft =>  0, Exp => 0);  New_Line;
  Put ( 0.10001, Fore =>  0, Aft =>  0, Exp => 0);  New_Line;
  Put ( 0.16001, Fore =>  0, Aft =>  0, Exp => 0);  New_Line;

end Test_Decimal_IO;

Expected output with patch:

0.0
-0.0
0.0
0.1
0.2

(before the patch the first three lines were outputting extra
digits after the point

Tested on x86_64-pc-linux-gnu, committed on trunk

2009-06-23  Robert Dewar  <dewar@adacore.com>

	* s-imgdec.adb (Set_Decimal_Digits): Fix error of too many digits for
	small values

Attachment: difs
Description: Text document


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