VHDL Issue Number: 1069 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: ISAC Approved 1076-1993 Disposition: N/A Disposition Rationale: N/A Superseded By: N/A ----------------------- 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: 1995/08/12 Author of Analysis: Clive R. Charlwood Revision Number: $Revision: 1.4 $ Date Last Revised: $Date: 1995/08/12 18:09:24 $ Description of Problem ---------------------- (This IR supersedes IR 0173.) Paragraph 2 of Section 7.2.6 (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 ------------------------------ We agree with the proposed resolution above. It appears that this is a simple oversight. VASG-ISAC Recommendation for IEEE Std 1076-1993 ----------------------------------------------- Read the LRM as if it included the above wording. VASG-ISAC Recommendation for Future Revisions --------------------------------------------- Change the LRM to included the above wording.