From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,948c0592e08fc494,start X-Google-Attributes: gid103376,public From: njt@minster.york.ac.uk (Nigel J. Tracey) Subject: Unchecked Conversion and 'Valid Date: 1996/10/07 Message-ID: <53anmp$2q3@netty.york.ac.uk>#1/1 X-Deja-AN: 187291579 organization: Dept. Computer Science, University of York. newsgroups: comp.lang.ada Date: 1996-10-07T00:00:00+00:00 List-Id: I am using unchecked conversion to generate random Floats over large ranges (up to Float'First..Float'Last). The problem is that it generates values which are out of the specified range for the float subtype, but 'Valid still says that the value is valid. Having tried the same thing for integer types the 'Valid attribute returns False if the number is out of range. My question is that if an array of bits is converted to a floating point sub-type (using unchecked conversion), should 'Valid indicate that the value is invalid if it is out of the sub-types range? The code I have used is below. The Valid attribute always appears to be true even when the value of Conv_Float is outside the range of My_Float. Thanks for any help, information or guidance, Nigel -------------------- Nigel J. Tracey MEng, Research Associate (High Integrity Systems Group). Department of Computer Science, Office: X/D016 University of York, Tel : [0|+44]1904 432769 York, England. E-Mail: njt@minster.york.ac.uk YO1 5DD. URL : http://sv1pc161.cs.york.ac.uk/~njt with Unchecked_Conversion; th Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random; with Text_IO; use Text_IO; procedure Unchecked is type My_Float is digits 6 range -3.0E+15..+3.0+E15; type Bit_Type is new integer range 0..1; for Bit_Type'Size use 1; type Bit_Array_Type is array(Integer range <>) of Bit_Type; for Bit_Array_Type'Component_Size use 1; pragma Pack(Bit_Array_Type); type Float_Bit_Array_Type is new Bit_Array_Type(1..My_Float'Size); function Bit_Array_To_Float is new Unchecked_Conversion(Float_Bit_Array_Type, My_Float); package Bit_IO is new Integer_IO(Bit_Type); use Bit_IO; package Int_IO is new Float_IO(My_Float) ; use Int_IO; Float_Bit_Array : Float_Bit_Array_Type; Gen : Generator; Conv_Float : My_Float; begin Reset(Gen); for I in 1..My_Float'Size loop if Random(Gen) > (0.5-Float'Small) then Float_Bit_Array(I) := 1; else Float_Bit_Array(I) := 0; end if; end loop; Conv_Float := Bit_Array_To_Float(Float_Bit_Array); Put_Line("The Float is"); Put(Conv_Float); New_Line; if Conv_Float'Valid then Put_Line("This value is Valid"); else Put_Line("This value is not Valid"); end if; end Unchecked;