diff options
author | Robert Dewar <dewar@adacore.com> | 2008-04-08 08:55:17 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2008-04-08 08:55:17 +0200 |
commit | fc5c20afff6cfc1139d2fafbb671cfcf7339e633 (patch) | |
tree | 606575cd1e87c03094b83637575a2f6aa6427b45 /gcc | |
parent | ca44152fc58297f5c0bef56190b6968549e1438e (diff) | |
download | gcc-fc5c20afff6cfc1139d2fafbb671cfcf7339e633.zip gcc-fc5c20afff6cfc1139d2fafbb671cfcf7339e633.tar.gz gcc-fc5c20afff6cfc1139d2fafbb671cfcf7339e633.tar.bz2 |
s-imgdec.adb (Set_Decimal_Digits): Fix error when input is zero with negative scale
2008-04-08 Robert Dewar <dewar@adacore.com>
* s-imgdec.adb (Set_Decimal_Digits): Fix error when input is zero with
negative scale
(Set_Decimal_Digits): Properly handle Aft=0 (equivalent to Aft=1)
Properly handle case where Aft > Scale and input number is less than
one.
From-SVN: r134050
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/s-imgdec.adb | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/gcc/ada/s-imgdec.adb b/gcc/ada/s-imgdec.adb index ce7365e..facafcb 100644 --- a/gcc/ada/s-imgdec.adb +++ b/gcc/ada/s-imgdec.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2007, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2008, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -129,6 +129,10 @@ package body System.Img_Dec is pragma Inline (Set_Zeroes); -- Set N zeroes, no effect if N is negative + ----------- + -- Round -- + ----------- + procedure Round (N : Natural) is D : Character; @@ -250,7 +254,7 @@ package body System.Img_Dec is if Exp > 0 then Set_Blanks_And_Sign (Fore - 1); - Round (Aft + 2); + Round (Digits_After_Point + 2); Set (Digs (FD)); FD := FD + 1; ND := ND - 1; @@ -258,7 +262,6 @@ package body System.Img_Dec is if ND >= Digits_After_Point then Set_Digits (FD, FD + Digits_After_Point - 1); - else Set_Digits (FD, LD); Set_Zeroes (Digits_After_Point - ND); @@ -317,27 +320,42 @@ package body System.Img_Dec is Set_Blanks_And_Sign (Fore - 1); Set ('0'); Set ('.'); - - Set_Zeroes (Digits_After_Point - ND); + Set_Zeroes (-Digits_Before_Point); Set_Digits (FD, LD); + Set_Zeroes (Digits_After_Point - Scale); -- At least one digit before point in input else - Set_Blanks_And_Sign (Fore - Digits_Before_Point); - -- Less digits in input than are needed before point -- Input: 1PP Output: 100.000 if ND < Digits_Before_Point then - Set_Digits (FD, LD); - Set_Zeroes (Digits_Before_Point - ND); + + -- Special case, if the input is the single digit 0, then we + -- do not want 000.000, but instead 0.000. + + if ND = 1 and then Digs (FD) = '0' then + Set_Blanks_And_Sign (Fore - 1); + Set ('0'); + + -- Normal case where we need to output scaling zeroes + + else + Set_Blanks_And_Sign (Fore - Digits_Before_Point); + Set_Digits (FD, LD); + Set_Zeroes (Digits_Before_Point - ND); + end if; + + -- Set period and zeroes after the period + Set ('.'); Set_Zeroes (Digits_After_Point); -- Input has full amount of digits before decimal point else + Set_Blanks_And_Sign (Fore - Digits_Before_Point); Set_Digits (FD, FD + Digits_Before_Point - 1); Set ('.'); Set_Digits (FD + Digits_Before_Point, LD); |