Integer_Part := To_UB_Text(Ada.Strings.Fixed.Trim(Source => Integer'Image(Integer(Integer_Part_F)), Side => Ada.Strings.Left));
Decimal_Part := To_UB_Text(Ada.Strings.Fixed.Trim(Source => Integer'Image(Decimal_Part_I), Side => Ada.Strings.Left));
- Prepend_Zeros_To_Text(Decimal_Part_F, ExpDecimals, Decimal_Part);
+ Prepend_Zeros_To_Text(Decimal_Part_F, Decimals, Decimal_Part);
end Split_Integer_Decimal_Unscaled_Strs;
procedure Split_Integer_Decimal_Exponent_Nums(Num: in FH_Float; Decimals: in Natural; Integer_Part: out Integer; Decimal_Part: out FH_Float; Exponent_Part: out Integer) is
Log_Arg_Floored := FH_Float'Floor(Log(Base => 10.0, X => PNum));
Expanded := 10.0 ** Log_Arg_Floored;
+ --PNum := Round_To_Valid_Nums(PNum, Decimals);
+ --Ada.Text_IO.Put_Line("EP: " & FH_Float'Image((PNum / Expanded) + EPSILON) & " N: " & FH_Float'Image(PNum / Expanded));
declare
FPE: constant FH_Float := FH_Float'Floor((PNum / Expanded) + EPSILON);
F: constant FH_Float := FH_Float'Floor(PNum / Expanded);
begin
+ --Ada.Text_IO.Put_Line("FPE: " & FH_Float'Image(FPE) & " F: " & FH_Float'Image(F));
if FPE > F then
- PNum := PNum + EPSILON;
+ PNum := PNum + (EPSILON * Expanded);
Integer_Part_F := FPE;
else
Integer_Part_F := F;
end if;
end;
+ --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
if Negative then
Integer_Part := Integer_Part * (-1);
end if;
- --Ada.Text_IO.Put_Line(FH_Float'Image(Num) & " --- " & Integer'Image(Integer_Part) & "," & FH_Float'Image(Decimal_Part) & "e" & Integer'Image(Exponent_Part));
+ --Ada.Text_IO.Put_Line(FH_Float'Image(Num) & " --- " & Integer'Image(Integer_Part) & "," & FH_Float'Image(Decimal_Part) & "e " & Integer'Image(Exponent_Part));
+ --Ada.Text_IO.Put_Line("---");
end Split_Integer_Decimal_Exponent_Nums;
procedure Split_Integer_Decimal_Exponent_Strs(Num: in FH_Float; Decimals: in Natural; Integer_Part: out UB_Text; Decimal_Part: out UB_Text;
Integer_Part := To_UB_Text(Ada.Strings.Fixed.Trim(Source => Integer'Image(Integer_Part_I), Side => Ada.Strings.Left));
Decimal_Part := To_UB_Text(Ada.Strings.Fixed.Trim(Source => Integer'Image(Decimal_Part_I), Side => Ada.Strings.Left));
- Prepend_Zeros_To_Text(Decimal_Part_F, ExpDecimals, Decimal_Part);
+ Prepend_Zeros_To_Text(Decimal_Part_F, Decimals, Decimal_Part);
Exponent_Part := To_UB_Text(Ada.Strings.Fixed.Trim(Source => Integer'Image(Exponent_Part_I), Side => Ada.Strings.Left));
end Split_Integer_Decimal_Exponent_Strs;
-- BEGIN: Private functions
- procedure Prepend_Zeros_To_Text(Num: in FH_Float; Decimals: in FH_Float; Text: in out UB_Text) is
+ procedure Prepend_Zeros_To_Text(Num: in FH_Float; Decimals: in Natural; Text: in out UB_Text) is
package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float);
use FHEF;
- Log_Dec: constant FH_Float := Log(Base => 10.0, X => Decimals);
+ EPSILON: constant FH_Float := 10.0 ** (-(FH_Float'Digits - 1));
Log_Num: FH_Float;
Diff: Integer;
Zero_String: UB_Text;
Log_Num := 1.0;
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
+ Log_Num := Log_Num + 1.0;
+ end if;
end if;
- Diff := Integer(Log_Dec - Log_Num);
- if Diff = 0 then
+ Diff := Decimals - Integer(Log_Num);
+ --Ada.Text_IO.Put_Line("Diff: " & Integer'Image(Diff));
+ if Diff <= 0 then
return;
end if;