]> Devoid-pointer.net GitWeb - Nine-Q.git/commitdiff
- Round decimal part instead of flooring it to zero if it's less than
authorMichal Malý <madcatxster@devoid-pointer.net>
Mon, 29 Dec 2014 15:35:16 +0000 (16:35 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Mon, 29 Dec 2014 15:35:16 +0000 (16:35 +0100)
  one
- Add EPSILON to decimal part in Prepend_Zeros to avoid yet another
  corner case

src/formatting_helpers.adb

index ac7836acbf98c12d0ee25eec6c8b1c08259ea144..2991f56d4ae5bd2c20ef56a9a9b91b1a0cbc1216 100644 (file)
@@ -1,5 +1,6 @@
 with Ada.Numerics.Generic_Elementary_Functions;
 with Ada.Strings.Fixed;
+--with Ada.Strings.Unbounded;
 --with Ada.Text_IO;
 
 package body Formatting_Helpers is
@@ -95,9 +96,7 @@ package body Formatting_Helpers is
     --Integer_Part_F := FH_Float'Floor(PNum / Expanded);
     --Ada.Text_IO.Put_Line("((PNum / Expanded) - Integer_Part_F) * Expanded = " & FH_Float'Image(((PNum / Expanded) - Integer_Part_F) * Expanded));
     Decimal_Part := ((PNum / Expanded) - Integer_Part_F) * ExpDecimals;
-    if Decimal_Part < 1.0 then
-      Decimal_Part := 0.0;
-    end if;
+    Decimal_Part := FH_Float'Rounding(Decimal_Part);
 
     Exponent_Part := Integer(Log_Arg_Floored);
     Integer_Part := Integer(Integer_Part_F);
@@ -164,19 +163,20 @@ package body Formatting_Helpers is
     package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float);
     use FHEF;
 
-    EPSILON: constant FH_Float := 10.0 ** (-(Decimals + 1));
+    EPSILON: constant FH_Float := 10.0 ** (-Decimals);
     VDIV: constant FH_Float := 10.0 ** Decimals;
     Log_Num: FH_Float;
     Diff: Integer;
     Zero_String: UB_Text;
+    RNum: FH_Float := Num + EPSILON;
   begin
     if Num = 0.0 then
       Log_Num := 1.0;
     else
-      Log_Num := FH_Float'Ceiling(Log(Base => 10.0, X => Num));
+      Log_Num := FH_Float'Ceiling(Log(Base => 10.0, X => RNum));
       --Ada.Text_IO.Put_Line("Log_Num: " & FH_Float'Image(Log_Num));
-      --Ada.Text_IO.Put_Line("Num: " & FH_Float'Image(Num));
-      if Abs(FH_Float'Remainder(Num, VDIV / 10.0)) <= EPSILON then
+      --Ada.Text_IO.Put_Line("Num: " & FH_Float'Image(Num) & " Rem: " & FH_Float'Image(FH_Float'Remainder(RNum , VDIV / 10.0)));
+      if Abs(FH_Float'Remainder(RNum, VDIV / 10.0)) <= EPSILON then
        --Ada.Text_IO.Put_Line("Fixing up zeros - divisible by 100");
        Log_Num := Log_Num + 1.0;
       end if;