VHDL Issue Number: 0173 Classification: Language Definition Problem Language Version: VHDL-87 Summary: Mod and rem are ill-defined when they return zero. Related Issues: None. Relevant LRM Sections: 7.2.4 Key Words and Phrases: mod, rem, modulus operator, remainder operator, multiplying operators Current Status: Submitted 1076-1993 Disposition: Superseded (ISAC Issues Outstanding) Disposition Rationale: N/A Superseded By: 1069 ----------------------- Date Submitted: 1991/03/15 Author of Submission: Paul Menchini Author's Affiliation: CAD Language Systems, Inc. Author's Post Address: P.O. Box 13036 Research Triangle Park, NC 27709-3036 Author's Phone Number: (919) 361-1913 Author's Fax Number: Author's Net Address: mench@clsi.com ----------------------- Date Analyzed: TBD Author of Analysis: TBD Revision Number: $Revision: 1.9 $ Date Last Revised: $Date: 1995/07/26 21:27:46 $ Description of Problem ---------------------- Paragraph 2 of Section 7.2.4 (on page 7-6) defines the sign of the result of the REM operator as "... (A REM B) has the sign of A...."n Similarly, paragraph 3 of the same section defines the sign of the result of the MOD operator as "... (A MOD B) has the sign of B...." Consider, however, the operations (-4 REM -2) and (-4 MOD -2). The answer to both of these operations is zero. However, since abs (-4 REM -2) = (-4 REM -2) and abs (-4 MOD -2) = (-4 MOD -2) the signs of the results of these operations cannot be negative. This problem appears to have been inherited from Ada, and there are, to my knowledge, no AIs issued in this area (Section 4.5.5 of the Ada LRM). However, Ada does include the following notes at the end of Section 4.5.5: For positive A and B, A/B is the quotient and A REM B is the remainder when A is divided by B. The following relations are satisfied by the REM operator: A REM (-B) = A REM B (-A) REM B = -(A REM B) For any integer K, the following identity holds: A MOD B = (A + K*B) MOD B Which serve to clarify Ada's intent. Proposed Resolution ------------------- Change the phrase "... (A REM B) has the sign of A...." to "... (A REM B) has the sign of A (unless the result is zero)...." in paragraph 2 of Section 7.2.4. Change the phrase "... (A MOD B) has the sign of B...." to "... (A MOD B) has the sign of B (unless the result is zero)...." in paragraph 3 of the same section. VASG-ISAC Analysis & Rationale ------------------------------ TBD VASG-ISAC Recommendation for IEEE Std 1076-1987 ----------------------------------------------- TBD VASG-ISAC Recommendation for Future Revisions --------------------------------------------- TBD