From ff7cc263e8b628cd26bcfb9c32c8436672aa2860 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Mon, 29 Dec 2014 15:13:38 +0100 Subject: [PATCH] Adjust the EPSILON in the Prepend_Zeros function to hopefully fix another bunch of corner cases --- bin/templates/footer.html | 2 +- src/formatting_helpers.adb | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bin/templates/footer.html b/bin/templates/footer.html index 8751ba7..5e570e6 100644 --- a/bin/templates/footer.html +++ b/bin/templates/footer.html @@ -2,7 +2,7 @@
diff --git a/src/formatting_helpers.adb b/src/formatting_helpers.adb index 7c404ed..ac7836a 100644 --- a/src/formatting_helpers.adb +++ b/src/formatting_helpers.adb @@ -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; -- 2.43.5