VHDL Issue Number: 1036 Classification: Language Definition Problem Language Version: VHDL-93 Summary: Integer subtypes & operations Related Issues: Supersedes 0189 Relevant LRM Sections: 3.1.2, 3.1.4, 7.2.4, 7.2.6, 7.3.5, 8.8 Key Words and Phrases: Integer Type Definition, Subtype, Range Constraints Current Status: Submitted 1076-1993 Disposition: N/A Disposition Rationale: N/A Superseded By: N/A ----------------------- Date Submitted: 1994/03/30 Author of Submission: Andy S. Tsay Author's Affiliation: Fintronic USA, Inc. Author's Post Address: 1360 Willow Road, Suite 205 Menlo Park, CA 94025 Author's Phone Number: 415-325-4474 X121 Author's Fax Number: 415-325-4940 Author's Net Address: tsay@fintronic.com ----------------------- Date Analyzed: TBD Author of Analysis: TBD Revision Number: $Revision: 1.7 $ Date Last Revised: $Date: 1995/05/13 21:58:22 $ Description of Problem ---------------------- The original question is "What is the result type of an expression in which arithmetic operations are performed on an integer subtype? Should the result be in the integer subtype range to be valid?" In the following example, should the result of "V1 * 2 / 4" be constrained by range 0 to 10 or not? What is the allowed range for this expression? If the result is not to be constrained by range 0 to 10, then the case statement in the example is error, and requires "when others" to complete the set of choices(LRM 8.8). package P is function F return BOOLEAN; end P; package body P is function F return BOOLEAN is type I1 is range 0 to 10; variable V1 : I1 := 7; begin case V1 * 2 /4 is when 0 to 5 => return TRUE; when 6 to 10 => return FALSE; -- when others => return FALSE; -- Is this required? end case; end F; end P; Proposed Resolution ------------------- TBD VASG-ISAC Analysis & Rationale ------------------------------ >>VASG Issue Number: 0189 >>Comment Author: Andy S. Tsay >>Comment Number: 02 >>Comment Date: 1994/03/21 >> >>An integer type declaration declares both an anonymous type and a named subtype >>of that anonymous type. The range of the anonymous type is selected by the >>implementation and may be different from type UNIVERSAL_INTEGER. The range of >>the named subtype is given range in the integer type declaration. >> >>LRM 7.2.4, and 7.2.6 specify that the types of left and right operands should be >>the same. LRM 3.1.2 specifies that integer literals are the literals of an >>anonymous predefined type that is called UNIVERSAL_INTEGER. LRM also specifies >>the implicit type conversion from UNIVERSAL_INTEGER into the corresponding value >>(if any) of the integer type(3.1.2, 7.3.5). >> >>Therefore, it is clear that the operations are defined for the anonymous integer >>type, and the result of "V1 * 2 /4" expression is the anonymous integer type whose >>range is selected by the implementation. The "when others" is required to complete >>the set of choices. >> >>The comment number 01 below regarding implicit conversion is not quite accurate, >>since LRM does not specify the implicit type conversion from an integer type into >>the UNIVERSAL_INTEGER. >> >>VASG Issue Number: 0189 >>Comment Author: Clive Charlwood for Sivaram Nayudu >>Comment Number: 01 >>Comment Date: 1991/03/23 >> >>LRM section 3.1.2 paragraph 4 specifies that integer literals are the literals >>of an anonymous predefined type that is called UNIVERSAL INTEGER. >> >>LRM section 7.2.4 specifies that the types of left and right operands should >>be the same. Given that they have to be same type, we can either convert >>integer literals to the subtype of V1 or convert V1 to UNIVERSAL INTEGER and >>perform arithmetic as though they both belong to UNIVERSAL INTEGER. We think >>the latter approach is more general and allows variety of expressions to be >>formed involving integer and floating point literals. >> >>The expression (V1 * 2/4) without any typemark is treated as belonging to >>INTEGER/UNIVERSAL INTEGER. Note that if the user wanted this expression to >>be treated as belonging to the subtype of V1, it could be achieved by either >>qualifying the expression (as I1'(V1* 2/4)) or using an explicit type >>conversion to the subtype V1 (as I1(V1 * 2/4)). >> >>Conclusion: >> LRM should clearly state the result type of expression involving integer >> and/or floating point literals where the result type of the expression is >> not explicitly specified. >> >> We recommend that the result type of expressions involving (sub)expressions >> of integer type should be treated as UNIVERSAL INTEGER and the result type >> of expressions involving (sub)expressions of floating point type should be >> treated as UNIVERSAL REAL and the result type of expressions involving >> (sub)expressions that have both integer and floating point type should be >> treated as UNIVERSAL REAL. TBD VASG-ISAC Recommendation for IEEE Std 1076-1993 ----------------------------------------------- TBD VASG-ISAC Recommendation for Future Revisions --------------------------------------------- TBD