digitalmars.D.bugs - [Issue 3165] New: What kind of integer division does D use?

d-bugmail puremagic.com writes:
```http://d.puremagic.com/issues/show_bug.cgi?id=3165

Summary: What kind of integer division does D use?
Product: D
Version: unspecified
Platform: All
URL: http://www.digitalmars.com/d/2.0/expression.html#MulEx
pression
OS/Version: All
Status: NEW
Keywords: spec
Severity: normal
Priority: P2
Component: www.digitalmars.com
AssignedTo: nobody puremagic.com
ReportedBy: m.helvensteijn gmail.com

Specify what kind of integer division D uses. The description is ambiguous when
one or both operands of / are negative. So, in other words, what does D return
from:

3 /  2
3 / -2
-3 /  2
-3 / -2

Such information should be part of the language specification.

--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
```
Jul 12 2009
d-bugmail puremagic.com writes:
```http://d.puremagic.com/issues/show_bug.cgi?id=3165

--- Comment #1 from Michiel Helvensteijn <m.helvensteijn gmail.com>  2009-07-12
14:11:52 PDT ---
I've ran the following test:

----------------------------------
import std.stdio;

int main() {
writefln(8/3);
writefln(8/(-3));
writefln((-8)/3);
writefln((-8)/(-3));
writefln(8%3);
writefln(8%(-3));
writefln((-8)%3);
writefln((-8)%(-3));

return 0;
}
----------------------------------

outputs the following

----------
2
-2
-2
2
2
2
-2
-2
----------

So DMD uses truncated division. The quotient rounds towards zero and the
remainder has the same sign as the dividend.

--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
```
Jul 12 2009
d-bugmail puremagic.com writes:
```http://d.puremagic.com/issues/show_bug.cgi?id=3165

Stewart Gordon <smjg iname.com> changed:

----------------------------------------------------------------------------
URL|http://www.digitalmars.com/ |http://www.digitalmars.com/
|d/2.0/expression.html#MulEx |d/1.0/expression.html#MulEx
|pression                    |pression
CC|                            |smjg iname.com
Blocks|                            |677

--- Comment #2 from Stewart Gordon <smjg iname.com>  2009-07-14 16:30:04 PDT ---
Changing URL since this is a D1 spec issue just the same.

But you could well ask why it defines it as undefined for % but makes no
comment at all (even on whether it's rounded up, down or off for +ve operands)
for /.

I've felt for ages that the programmer ought to have the choice between trunc
and floor versions for both
http://www.digitalmars.com/d/archives/digitalmars/D/13125.html
but that's another matter.

--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
```
Jul 14 2009
d-bugmail puremagic.com writes:
```http://d.puremagic.com/issues/show_bug.cgi?id=3165

Walter Bright <bugzilla digitalmars.com> changed:

----------------------------------------------------------------------------
Status|NEW                         |RESOLVED
CC|                            |bugzilla digitalmars.com
Resolution|                            |FIXED

--- Comment #3 from Walter Bright <bugzilla digitalmars.com>  2009-09-03
13:25:32 PDT ---
Fixed dmd 1.047 and 2.032

--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
```
Sep 03 2009