From: Michal MalĂ˝ Date: Tue, 23 Dec 2014 18:52:32 +0000 (+0100) Subject: Allow negative numbers in Split_Int_Dec_Exp_Nums X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=3b49f0bc461e8ccb84d9400db4f3fa3a533e9fcd;p=Nine-Q.git Allow negative numbers in Split_Int_Dec_Exp_Nums --- diff --git a/src/formatting_helpers.adb b/src/formatting_helpers.adb index b59049d..63a8050 100644 --- a/src/formatting_helpers.adb +++ b/src/formatting_helpers.adb @@ -55,10 +55,12 @@ package body Formatting_Helpers is package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float); use FHEF; + ExpDecimals: constant FH_Float := 10.0 ** Decimals; + PNum: FH_Float; Expanded: FH_Float; Integer_Part_F: FH_Float; Log_Arg_Floored: FH_Float; - ExpDecimals: constant FH_Float := 10.0 ** Decimals; + Negative: Boolean; begin if Num = 0.0 then Integer_Part := 0; @@ -67,15 +69,26 @@ package body Formatting_Helpers is return; end if; - Log_Arg_Floored := FH_Float'Floor(Log(Base => 10.0, X => Num)); + if Num < 0.0 then + Negative := True; + PNum := Num * (-1.0); + else + PNum := Num; + Negative := False; + end if; + + Log_Arg_Floored := FH_Float'Floor(Log(Base => 10.0, X => PNum)); Expanded := 10.0 ** Log_Arg_Floored; - Integer_Part_F := FH_Float'Floor(Num / Expanded); - Decimal_Part := ((Num - (Integer_Part_F * Expanded)) / Expanded) * ExpDecimals; + Integer_Part_F := FH_Float'Floor(PNum / Expanded); + Decimal_Part := ((PNum - (Integer_Part_F * Expanded)) / Expanded) * ExpDecimals; Exponent_Part := Integer(Log_Arg_Floored); Integer_Part := Integer(Integer_Part_F); + 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)); end Split_Integer_Decimal_Exponent_Nums;