]> Devoid-pointer.net GitWeb - Nine-Q.git/commitdiff
Adjust the EPSILON in the Prepend_Zeros function to hopefully fix
authorMichal Malý <madcatxster@devoid-pointer.net>
Mon, 29 Dec 2014 14:13:38 +0000 (15:13 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Mon, 29 Dec 2014 14:13:38 +0000 (15:13 +0100)
another bunch of corner cases

bin/templates/footer.html
src/formatting_helpers.adb

index 8751ba7d5a47a323cbe93dfebad771501658e3e9..5e570e67bce04ed684bb4c9ab60754f5bdf96061 100644 (file)
@@ -2,7 +2,7 @@
     <div id="spacer"></div>
     <div id="footer">
       <span id="core_info">Powered by: <a class="footer_link" href="http://libre.adacore.com/tools/aws/">AWS</a> | <a class="footer_link" href="http://gitweb.devoid-pointer.net/?p=Nine-Q.git;a=summary">Nine-Q</a> | <a class="footer_link" href="http://archlinux.org">Arch Linux</a></span>
-      <span id="nineq_version_tag">Ver.:&nbsp;0.03A</span>
+      <span id="nineq_version_tag">Ver.:&nbsp;0.03B</span>
     </div>
   </div>
 </body>
index 7c404edf8cd3d50b77c3f17d49964b0e0ef2a3e4..ac7836acbf98c12d0ee25eec6c8b1c08259ea144 100644 (file)
@@ -43,7 +43,18 @@ package body Formatting_Helpers is
     ExpDecimals: constant FH_Float := 10.0 ** Decimals;
     MNum: FH_Float := Num;
   begin
-    Integer_Part_F := FH_Float'Floor(MNum);
+    declare
+      EPSILON: constant FH_Float := 10.0 ** (-(Decimals + 1));
+      FPE: constant FH_Float := FH_Float'Floor(MNum + EPSILON);
+      F: constant FH_Float := FH_Float'Floor(MNum);
+    begin
+      if FPE > F then
+       Integer_Part_F := FPE;
+       MNum := MNum + EPSILON;
+      else
+       Integer_Part_F := F;
+      end if;
+    end;
     Decimal_Part_F := (MNum - Integer_Part_F) * ExpDecimals;
     Decimal_Part_I := Integer(Decimal_Part_F);
 
@@ -153,7 +164,8 @@ package body Formatting_Helpers is
     package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float);
     use FHEF;
 
-    EPSILON: constant FH_Float := 10.0 ** (-(FH_Float'Digits - 1));
+    EPSILON: constant FH_Float := 10.0 ** (-(Decimals + 1));
+    VDIV: constant FH_Float := 10.0 ** Decimals;
     Log_Num: FH_Float;
     Diff: Integer;
     Zero_String: UB_Text;
@@ -163,8 +175,9 @@ package body Formatting_Helpers is
     else
       Log_Num := FH_Float'Ceiling(Log(Base => 10.0, X => Num));
       --Ada.Text_IO.Put_Line("Log_Num: " & FH_Float'Image(Log_Num));
-      --Ada.Text_IO.Put_Line("NRem: " & FH_Float'Image(FH_Float'Remainder(Num, 10.0)));
-      if Abs(FH_Float'Remainder(Num, 100.0)) <= EPSILON then
+      --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("Fixing up zeros - divisible by 100");
        Log_Num := Log_Num + 1.0;
       end if;
     end if;