www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9717] New: `std.math.round` rounds away from zero instead of to the nearest even integer

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

           Summary: `std.math.round` rounds away from zero instead of to
                    the nearest even integer
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



15:16:12 MSK ---
Rounding to the nearest even integer is a default rounding mode and is an
expected, useful (e.g. for mesurements rounding), and documented behaviour for
`std.math.round`. But instead it currently rounds away from zero (it even uses
C's `roundl`).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 14 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9717


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx



Do you have an example code for this bug? I did this:

void main() { writeln(std.math.round(1.4)); }

and the output is 1, as expected.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9717


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com




 Do you have an example code for this bug? I did this:
 
 void main() { writeln(std.math.round(1.4)); }
 
 and the output is 1, as expected.
I believe the "nearest even" is for the .5 tie-breakers: EG: round(0.5) == 0 round(1.5) == 2 round(2.5) == 2 It sounds strange at first, but it keeps things "sign agnostic" and nor shifts the average. http://en.wikipedia.org/wiki/Rounding#Round_half_to_even -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9717




That said, "nearest half" is one scheme among many other. I'm not sure about
"default".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9717




10:42:37 MSK ---

 That said, "nearest half" is one scheme among many other. I'm not sure about
 "default".
I mean the function is documented to behave this way: http://dlang.org/phobos/std_math.html#round Also I haven't seen examples where you have to use another theme but I saw ones where you have to use "half to even" theme. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 16 2013