digitalmars.D.bugs - [Issue 7728] New: Alternative div and mod in core.bitop
- d-bugmail puremagic.com (56/56) Mar 18 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7728
- d-bugmail puremagic.com (6/6) Sep 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7728
- d-bugmail puremagic.com (12/12) Sep 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7728
http://d.puremagic.com/issues/show_bug.cgi?id=7728 Summary: Alternative div and mod in core.bitop Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc --- Comment #0 from bearophile_hugs eml.cc 2012-03-18 06:04:33 PDT --- When I translate Python code to D I sometimes need in D the different integer division and the different modulo operation of Python3. They give different results with the operands are negative: Python2 code: for x in xrange(-10, 1): print x, "", x % 3, "", x // 3 Python output: -10 2 -4 -9 0 -3 -8 1 -3 -7 2 -3 -6 0 -2 -5 1 -2 -4 2 -2 -3 0 -1 -2 1 -1 -1 2 -1 0 0 0 D code: import std.stdio; void main() { foreach (x; -10 .. 1) writeln(x, " ", x % 3, " ", x / 3); } D output: -10 -1 -3 -9 0 -3 -8 -2 -2 -7 -1 -2 -6 0 -2 -5 -2 -1 -4 -1 -1 -3 0 -1 -2 -2 0 -1 -1 0 0 0 0 So I suggest to add both simple functions to Phobos, possibly as efficient compiler intrinsics (this means inlined asm) in core.bitop. It seems Ada and CommonLisp have functions for both needs: http://en.wikipedia.org/wiki/Modulo_operation -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 18 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7728 --- Comment #1 from bearophile_hugs eml.cc 2012-09-16 13:32:15 PDT --- See also an alternative proposal, Issue 8672 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7728 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |DUPLICATE --- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2012-09-16 14:46:20 PDT --- *** This issue has been marked as a duplicate of issue 8672 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 16 2012