* Incorporate decimal conversion to conversion function
This commit is contained in:
parent
07c225238b
commit
ba4359ae59
|
@ -32,6 +32,26 @@ is
|
||||||
(S'Length >= 4 and then S (S'First) in 'B' | 'b' | 'O' | 'o' | 'Z' | 'z' and then
|
(S'Length >= 4 and then S (S'First) in 'B' | 'b' | 'O' | 'o' | 'Z' | 'z' and then
|
||||||
S (S'First + 1) = S (S'Last) and then S (S'Last) in ''' | '"'); --"
|
S (S'First + 1) = S (S'Last) and then S (S'Last) in ''' | '"'); --"
|
||||||
|
|
||||||
|
-- Convert simple decimal number
|
||||||
|
function Decimal (S : String) return Exponent_Type is
|
||||||
|
N : Exponent_Type := 0;
|
||||||
|
D : Exponent_Type;
|
||||||
|
begin
|
||||||
|
for C of S loop
|
||||||
|
if C in '0' .. '9' then
|
||||||
|
D := Character'Pos (C) - Character'Pos ('0');
|
||||||
|
if N > (Exponent_Type'Last - D) / 10 then
|
||||||
|
return Exponent_Type'First; -- carefully treat overflow
|
||||||
|
end if; -- to have meaningfull exception
|
||||||
|
N := N * 10 + D;
|
||||||
|
elsif C not in NUL .. ' ' | '|' then
|
||||||
|
raise Constraint_Error with "Illegal character " & Character'Image (C);
|
||||||
|
end if;
|
||||||
|
end loop;
|
||||||
|
return N;
|
||||||
|
end Decimal;
|
||||||
|
|
||||||
|
-- Convert mantissa
|
||||||
procedure Mantissa (
|
procedure Mantissa (
|
||||||
S : in String;
|
S : in String;
|
||||||
R : in Radix_Type;
|
R : in Radix_Type;
|
||||||
|
@ -173,7 +193,7 @@ begin
|
||||||
end loop Radix_Find;
|
end loop Radix_Find;
|
||||||
|
|
||||||
if Based then
|
if Based then
|
||||||
Radix := Decimal_to_Number (S (RF .. RL));
|
Radix := Integer (Decimal (S (RF .. RL)));
|
||||||
-- raise constraint error when not in range
|
-- raise constraint error when not in range
|
||||||
elsif not Based then
|
elsif not Based then
|
||||||
Dec_Exp_Find : for J in MF + 1 .. ML - 1 loop
|
Dec_Exp_Find : for J in MF + 1 .. ML - 1 loop
|
||||||
|
@ -202,7 +222,7 @@ begin
|
||||||
|
|
||||||
if Exp then
|
if Exp then
|
||||||
Sign (S, EF, EL, NE);
|
Sign (S, EF, EL, NE);
|
||||||
EE := Decimal_to_Number (S (EF .. EL));
|
EE := Decimal (S (EF .. EL));
|
||||||
if EE < 0 then
|
if EE < 0 then
|
||||||
raise Constraint_Error with "Exponent value is out of range";
|
raise Constraint_Error with "Exponent value is out of range";
|
||||||
end if;
|
end if;
|
||||||
|
|
|
@ -15,9 +15,6 @@ generic
|
||||||
with function To_Number (
|
with function To_Number (
|
||||||
A : Integer)
|
A : Integer)
|
||||||
return Number_Type is <>; -- A function to convert a digit to a given type
|
return Number_Type is <>; -- A function to convert a digit to a given type
|
||||||
with function Decimal_to_Number (
|
|
||||||
S : String)
|
|
||||||
return Exponent_Type is <>; -- A function to convert decimal digits to number
|
|
||||||
with function Multiply_by_Power (
|
with function Multiply_by_Power (
|
||||||
A,
|
A,
|
||||||
R : Number_Type;
|
R : Number_Type;
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
with Ada.Characters.Latin_1;
|
|
||||||
use Ada.Characters.Latin_1;
|
|
||||||
|
|
||||||
package body VSSL.Conversions is
|
|
||||||
|
|
||||||
function Decimal_to_Number (S : String) return Integer is
|
|
||||||
N : Integer := 0;
|
|
||||||
D : Integer;
|
|
||||||
begin
|
|
||||||
for C of S loop
|
|
||||||
if C in '0' .. '9' then
|
|
||||||
D := Character'Pos (C) - Character'Pos ('0');
|
|
||||||
if N > (Integer'Last - D) / 10 then
|
|
||||||
return Integer'First; -- carefully treat overflow
|
|
||||||
end if; -- to have meaningfull exception
|
|
||||||
N := N * 10 + D;
|
|
||||||
elsif C not in NUL .. ' ' | '|' then
|
|
||||||
raise Constraint_Error with "Illegal character " & Character'Image (C);
|
|
||||||
end if;
|
|
||||||
end loop;
|
|
||||||
return N;
|
|
||||||
end Decimal_to_Number;
|
|
||||||
|
|
||||||
end VSSL.Conversions;
|
|
|
@ -8,10 +8,4 @@ package VSSL.Conversions with Pure is
|
||||||
return Integer is (if N >= 0 then A * R**N else A / R**(-N));
|
return Integer is (if N >= 0 then A * R**N else A / R**(-N));
|
||||||
-- used by conversion subprograms
|
-- used by conversion subprograms
|
||||||
|
|
||||||
function Decimal_to_Number (
|
|
||||||
S : String)
|
|
||||||
return Integer;
|
|
||||||
-- Convert decimal number (without a sign) to an integer
|
|
||||||
-- It is used by conversion subprograms
|
|
||||||
|
|
||||||
end VSSL.Conversions;
|
end VSSL.Conversions;
|
||||||
|
|
Loading…
Reference in New Issue