-- C460011.A
|
-- C460011.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687 and
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687 and
|
-- F08630-91-C-0015, the U.S. Government obtained unlimited rights in the
|
-- F08630-91-C-0015, the U.S. Government obtained unlimited rights in the
|
-- software and documentation contained herein. Unlimited rights are
|
-- software and documentation contained herein. Unlimited rights are
|
-- defined in DFAR 252.227-7013(a)(19). By making this public release,
|
-- defined in DFAR 252.227-7013(a)(19). By making this public release,
|
-- the Government intends to confer upon all recipients unlimited rights
|
-- the Government intends to confer upon all recipients unlimited rights
|
-- equal to those held by the Government. These rights include rights to
|
-- equal to those held by the Government. These rights include rights to
|
-- use, duplicate, release or disclose the released technical data and
|
-- use, duplicate, release or disclose the released technical data and
|
-- computer software in whole or in part, in any manner and for any purpose
|
-- computer software in whole or in part, in any manner and for any purpose
|
-- whatsoever, and to have or permit others to do so.
|
-- whatsoever, and to have or permit others to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that conversion of a decimal type to a modular type raises
|
-- Check that conversion of a decimal type to a modular type raises
|
-- Constraint_Error when the operand value is outside the base range
|
-- Constraint_Error when the operand value is outside the base range
|
-- of the modular type.
|
-- of the modular type.
|
-- Check that a conversion of a decimal type to an integer type
|
-- Check that a conversion of a decimal type to an integer type
|
-- rounds correctly.
|
-- rounds correctly.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- Test conversion from decimal types to modular types. Test
|
-- Test conversion from decimal types to modular types. Test
|
-- conversion to mod 255, mod 256 and mod 258 to test the boundaries
|
-- conversion to mod 255, mod 256 and mod 258 to test the boundaries
|
-- of 8 bit (+/-) unsigned numbers.
|
-- of 8 bit (+/-) unsigned numbers.
|
-- Test operand values that are negative, the value of the mod,
|
-- Test operand values that are negative, the value of the mod,
|
-- and greater than the value of the mod.
|
-- and greater than the value of the mod.
|
-- Declare a generic test procedure and instantiate it for each of the
|
-- Declare a generic test procedure and instantiate it for each of the
|
-- unsigned types for each operand type.
|
-- unsigned types for each operand type.
|
-- Check that the the operand is properly rounded during the conversion.
|
-- Check that the the operand is properly rounded during the conversion.
|
--
|
--
|
-- APPLICABILITY CRITERIA:
|
-- APPLICABILITY CRITERIA:
|
-- This test is applicable to all implementations which support
|
-- This test is applicable to all implementations which support
|
-- decimal types.
|
-- decimal types.
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 24 NOV 98 RLB Split decimal cases from C460008 into this
|
-- 24 NOV 98 RLB Split decimal cases from C460008 into this
|
-- test, added conversions to integer types.
|
-- test, added conversions to integer types.
|
-- 18 JAN 99 RLB Repaired errors in test.
|
-- 18 JAN 99 RLB Repaired errors in test.
|
--
|
--
|
--!
|
--!
|
|
|
------------------------------------------------------------------- C460011
|
------------------------------------------------------------------- C460011
|
|
|
with Report;
|
with Report;
|
|
|
procedure C460011 is
|
procedure C460011 is
|
|
|
Shy_By_One : constant := 2**8-1;
|
Shy_By_One : constant := 2**8-1;
|
Heavy_By_Two : constant := 2**8+2;
|
Heavy_By_Two : constant := 2**8+2;
|
|
|
type Unsigned_Edge_8 is mod Shy_By_One;
|
type Unsigned_Edge_8 is mod Shy_By_One;
|
type Unsigned_8_Bit is mod 2**8;
|
type Unsigned_8_Bit is mod 2**8;
|
type Unsigned_Over_8 is mod Heavy_By_Two;
|
type Unsigned_Over_8 is mod Heavy_By_Two;
|
|
|
type Signed_8_Bit is range -128 .. 127;
|
type Signed_8_Bit is range -128 .. 127;
|
type Signed_Over_8 is range -200 .. 200;
|
type Signed_Over_8 is range -200 .. 200;
|
|
|
NPC : constant String := " not properly converted";
|
NPC : constant String := " not properly converted";
|
|
|
procedure Assert( Truth: Boolean; Message: String ) is
|
procedure Assert( Truth: Boolean; Message: String ) is
|
begin
|
begin
|
if not Truth then
|
if not Truth then
|
Report.Failed(Message);
|
Report.Failed(Message);
|
end if;
|
end if;
|
end Assert;
|
end Assert;
|
|
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
type Decim is delta 0.1 digits 5; -- N/A => ERROR.
|
type Decim is delta 0.1 digits 5; -- N/A => ERROR.
|
|
|
generic
|
generic
|
type Source is delta <> digits <>;
|
type Source is delta <> digits <>;
|
type Target is mod <>;
|
type Target is mod <>;
|
procedure Decimal_Conversion_Check( For_The_Value : Source;
|
procedure Decimal_Conversion_Check( For_The_Value : Source;
|
Message : String );
|
Message : String );
|
|
|
procedure Decimal_Conversion_Check( For_The_Value : Source;
|
procedure Decimal_Conversion_Check( For_The_Value : Source;
|
Message : String ) is
|
Message : String ) is
|
|
|
Item : Target;
|
Item : Target;
|
|
|
begin
|
begin
|
Item := Target( For_The_Value );
|
Item := Target( For_The_Value );
|
Report.Failed("Deci expected Constraint_Error " & Message);
|
Report.Failed("Deci expected Constraint_Error " & Message);
|
Report.Comment("Value of" & Target'Image(Item) & NPC);
|
Report.Comment("Value of" & Target'Image(Item) & NPC);
|
exception
|
exception
|
when Constraint_Error => null; -- expected case
|
when Constraint_Error => null; -- expected case
|
when others => Report.Failed("Deci raised wrong exception " & Message);
|
when others => Report.Failed("Deci raised wrong exception " & Message);
|
end Decimal_Conversion_Check;
|
end Decimal_Conversion_Check;
|
|
|
procedure Decim_To_Short is
|
procedure Decim_To_Short is
|
new Decimal_Conversion_Check( Decim, Unsigned_Edge_8 );
|
new Decimal_Conversion_Check( Decim, Unsigned_Edge_8 );
|
|
|
procedure Decim_To_Eight is
|
procedure Decim_To_Eight is
|
new Decimal_Conversion_Check( Decim, Unsigned_8_Bit );
|
new Decimal_Conversion_Check( Decim, Unsigned_8_Bit );
|
|
|
procedure Decim_To_Wide is
|
procedure Decim_To_Wide is
|
new Decimal_Conversion_Check( Decim, Unsigned_Over_8 );
|
new Decimal_Conversion_Check( Decim, Unsigned_Over_8 );
|
|
|
function Identity( Launder: Decim ) return Decim is
|
function Identity( Launder: Decim ) return Decim is
|
Flat_Broke : constant Decim := 0.0;
|
Flat_Broke : constant Decim := 0.0;
|
begin
|
begin
|
if Report.Ident_Bool( Launder = Flat_Broke ) then
|
if Report.Ident_Bool( Launder = Flat_Broke ) then
|
return Flat_Broke;
|
return Flat_Broke;
|
else
|
else
|
return Launder;
|
return Launder;
|
end if;
|
end if;
|
end Identity;
|
end Identity;
|
|
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
begin -- Main test procedure.
|
begin -- Main test procedure.
|
|
|
Report.Test ("C460011", "Check that conversion to " &
|
Report.Test ("C460011", "Check that conversion to " &
|
"a modular type raises Constraint_Error when " &
|
"a modular type raises Constraint_Error when " &
|
"the operand value is outside the base range " &
|
"the operand value is outside the base range " &
|
"of the modular type" );
|
"of the modular type" );
|
|
|
-- Decimal Error cases
|
-- Decimal Error cases
|
|
|
Decim_To_Short( Identity( -5.00 ), "M2S Dynamic, Negative" );
|
Decim_To_Short( Identity( -5.00 ), "M2S Dynamic, Negative" );
|
Decim_To_Short( Shy_By_One * 1.0, "M2S Static, At_Mod" );
|
Decim_To_Short( Shy_By_One * 1.0, "M2S Static, At_Mod" );
|
Decim_To_Short( 1995.9, "M2S Static, Over_Mod" );
|
Decim_To_Short( 1995.9, "M2S Static, Over_Mod" );
|
|
|
Decim_To_Eight( -0.5, "M28 Static, Negative" );
|
Decim_To_Eight( -0.5, "M28 Static, Negative" );
|
Decim_To_Eight( 2.0*128, "M28 Static, At_Mod" );
|
Decim_To_Eight( 2.0*128, "M28 Static, At_Mod" );
|
Decim_To_Eight( Identity( 2001.2 ), "M28 Dynamic, Over_Mod" );
|
Decim_To_Eight( Identity( 2001.2 ), "M28 Dynamic, Over_Mod" );
|
|
|
Decim_To_Wide ( Decim'First, "M2W Static, Negative" );
|
Decim_To_Wide ( Decim'First, "M2W Static, Negative" );
|
Decim_To_Wide ( Identity( 2*128.0 +2.0 ), "M2W Dynamic, At_Mod" );
|
Decim_To_Wide ( Identity( 2*128.0 +2.0 ), "M2W Dynamic, At_Mod" );
|
Decim_To_Wide ( Decim'Last, "M2W Static, Over_Mod" );
|
Decim_To_Wide ( Decim'Last, "M2W Static, Over_Mod" );
|
|
|
-- Check a few, correct, edge cases, for modular types.
|
-- Check a few, correct, edge cases, for modular types.
|
|
|
Eye_Dew: declare
|
Eye_Dew: declare
|
Sense : Decim := 0.00;
|
Sense : Decim := 0.00;
|
|
|
Little : Unsigned_Edge_8;
|
Little : Unsigned_Edge_8;
|
Moderate : Unsigned_8_Bit;
|
Moderate : Unsigned_8_Bit;
|
Big : Unsigned_Over_8;
|
Big : Unsigned_Over_8;
|
|
|
begin
|
begin
|
Moderate := Unsigned_8_Bit (Sense);
|
Moderate := Unsigned_8_Bit (Sense);
|
Assert( Moderate = 0, "Sense => Moderate, 0");
|
Assert( Moderate = 0, "Sense => Moderate, 0");
|
|
|
Sense := 2*128.0;
|
Sense := 2*128.0;
|
|
|
Big := Unsigned_Over_8 (Sense);
|
Big := Unsigned_Over_8 (Sense);
|
Assert( Big = 256, "Sense => Big, 256");
|
Assert( Big = 256, "Sense => Big, 256");
|
|
|
end Eye_Dew;
|
end Eye_Dew;
|
|
|
Rounding: declare
|
Rounding: declare
|
Easy : Decim := Identity ( 2.0);
|
Easy : Decim := Identity ( 2.0);
|
Simple : Decim := Identity ( 2.1);
|
Simple : Decim := Identity ( 2.1);
|
Halfway : Decim := Identity ( 2.5);
|
Halfway : Decim := Identity ( 2.5);
|
Upward : Decim := Identity ( 2.8);
|
Upward : Decim := Identity ( 2.8);
|
Chop : Decim := Identity (-2.2);
|
Chop : Decim := Identity (-2.2);
|
Neg_Half : Decim := Identity (-2.5);
|
Neg_Half : Decim := Identity (-2.5);
|
Downward : Decim := Identity (-2.7);
|
Downward : Decim := Identity (-2.7);
|
|
|
Little : Unsigned_Edge_8;
|
Little : Unsigned_Edge_8;
|
Moderate : Unsigned_8_Bit;
|
Moderate : Unsigned_8_Bit;
|
Big : Unsigned_Over_8;
|
Big : Unsigned_Over_8;
|
|
|
Also_Little:Signed_8_Bit;
|
Also_Little:Signed_8_Bit;
|
Also_Big : Signed_Over_8;
|
Also_Big : Signed_Over_8;
|
|
|
begin
|
begin
|
Little := Unsigned_Edge_8 (Easy);
|
Little := Unsigned_Edge_8 (Easy);
|
Assert( Little = 2, "Easy => Little, 2");
|
Assert( Little = 2, "Easy => Little, 2");
|
|
|
Moderate := Unsigned_8_Bit (Simple);
|
Moderate := Unsigned_8_Bit (Simple);
|
Assert( Moderate = 2, "Simple => Moderate, 2");
|
Assert( Moderate = 2, "Simple => Moderate, 2");
|
|
|
Big := Unsigned_Over_8 (Halfway); -- Rounds up by 4.6(33).
|
Big := Unsigned_Over_8 (Halfway); -- Rounds up by 4.6(33).
|
Assert( Big = 3, "Halfway => Big, 3");
|
Assert( Big = 3, "Halfway => Big, 3");
|
|
|
Little := Unsigned_Edge_8 (Upward);
|
Little := Unsigned_Edge_8 (Upward);
|
Assert( Little = 3, "Upward => Little, 3");
|
Assert( Little = 3, "Upward => Little, 3");
|
|
|
Also_Big := Signed_Over_8 (Halfway); -- Rounds up by 4.6(33).
|
Also_Big := Signed_Over_8 (Halfway); -- Rounds up by 4.6(33).
|
Assert( Also_Big = 3, "Halfway => Also_Big, 3");
|
Assert( Also_Big = 3, "Halfway => Also_Big, 3");
|
|
|
Also_Little := Signed_8_Bit (Chop);
|
Also_Little := Signed_8_Bit (Chop);
|
Assert( Also_Little = -2, "Chop => Also_Little, -2");
|
Assert( Also_Little = -2, "Chop => Also_Little, -2");
|
|
|
Also_Big := Signed_Over_8 (Neg_Half); -- Rounds down by 4.6(33).
|
Also_Big := Signed_Over_8 (Neg_Half); -- Rounds down by 4.6(33).
|
Assert( Also_Big = -3, "Halfway => Also_Big, -3");
|
Assert( Also_Big = -3, "Halfway => Also_Big, -3");
|
|
|
Also_Little := Signed_8_Bit (Downward);
|
Also_Little := Signed_8_Bit (Downward);
|
Assert( Also_Little = -3, "Downward => Also_Little, -3");
|
Assert( Also_Little = -3, "Downward => Also_Little, -3");
|
|
|
end Rounding;
|
end Rounding;
|
|
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end C460011;
|
end C460011;
|
|
|