From: Robert Dewar Date: Tue, 8 Apr 2008 06:55:17 +0000 (+0200) Subject: s-imgdec.adb (Set_Decimal_Digits): Fix error when input is zero with negative scale X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fc5c20afff6cfc1139d2fafbb671cfcf7339e633;p=gcc.git s-imgdec.adb (Set_Decimal_Digits): Fix error when input is zero with negative scale 2008-04-08 Robert Dewar * 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 --- diff --git a/gcc/ada/s-imgdec.adb b/gcc/ada/s-imgdec.adb index ce7365eb2a6..facafcb495f 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);