package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float);
use FHEF;
+ EPSILON: constant FH_Float := 10.0 ** (-(Decimals + 1));
ExpDecimals: constant FH_Float := 10.0 ** Decimals;
PNum: FH_Float;
Expanded: FH_Float;
Log_Arg_Floored := FH_Float'Floor(Log(Base => 10.0, X => PNum));
Expanded := 10.0 ** Log_Arg_Floored;
- Integer_Part_F := FH_Float'Floor(PNum / Expanded);
- Decimal_Part := ((PNum - (Integer_Part_F * Expanded)) / Expanded) * ExpDecimals;
+ declare
+ FPE: constant FH_Float := FH_Float'Floor((PNum / Expanded) + EPSILON);
+ F: constant FH_Float := FH_Float'Floor(PNum / Expanded);
+ begin
+ if FPE > F then
+ PNum := PNum + EPSILON;
+ Integer_Part_F := FPE;
+ else
+ Integer_Part_F := F;
+ end if;
+ end;
+ --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;
Exponent_Part := Integer(Log_Arg_Floored);
Integer_Part := Integer(Integer_Part_F);