Related articles |
---|
Constant divisions, remainders rutt@paradise.mti.sgi.com (1992-10-20) |
Re: Constant divisions, remainders Cheryl_Lins@gateway.qm.apple.com (Cheryl Lins) (1992-10-21) |
Re: Constant divisions, remainders phillips@swanee.ee.uwa.oz.au (1992-10-23) |
Re: Constant divisions, remainders kelsey@flora.ccs.northeastern.edu (1992-10-27) |
Re: Constant divisions, remainders torbenm@diku.dk (1992-11-02) |
Re: Constant divisions, remainders joe@babel.ho.att.com (1992-11-05) |
Re: Constant divisions, remainders henry@zoo.toronto.edu (1992-11-08) |
Re: Constant divisions, remainders jones@pyrite.cs.uiowa.edu (1992-11-11) |
Re: Constant divisions, remainders nickh@CS.CMU.EDU (1992-11-11) |
Re: Constant divisions, remainders preston@miranda.cs.rice.edu (1992-11-11) |
Re: Constant divisions, remainders jlg@cochiti.lanl.gov (1992-11-12) |
[2 later articles] |
Newsgroups: | comp.compilers |
From: | torbenm@diku.dk (Torben AEgidius Mogensen) |
Organization: | Department of Computer Science, U of Copenhagen |
Date: | Mon, 2 Nov 1992 14:45:02 GMT |
Keywords: | arithmetic |
References: | 92-10-075 92-10-106 |
kelsey@flora.ccs.northeastern.edu writes:
[Right shift isn't the same as division when the dividend is negative.]
This depends on how you define div and mod for negative integers. The most
usually found "definition" is that div rounds towards 0, and that mod is
signed. But most mathematicians prefer to make div always round down and
that mod is nonnegative. Given this definition it is perfectly valid to
replace x div 2**n by x>>n on two's complement machines. Some languages
(like Standard ML) define div and mod in this way, and the ANSII standard
for C is unspecified on this point, that is, it allows either definition
of div and mod as long as they are consistent.
I think the round-to-zero rule for div and signed mod are relics from ones
complement computers, and should be laid to rest.
Torben Mogensen (torbenm@diku.dk)
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.