Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
ruby rounding?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Kyle Schmitt, post: 4556227"] Something interesting came up at work concerning rounding. Notably, that the round procedure in vb.net was good for stats (round to even), but since what the programmers expected (symmetric arithmetic rounding) was different, some edge cases were failing their tests. This got me thinking, what does Ruby use for rounding? It turns out (example below) it's symmetric arithmetic rounding. But the methods in C's math.h give the programmer a choice of which rounding method to use. Since there's so much development going on in Ruby currently, maybe something like this could be/should be added. See [URL]http://en.wikipedia.org/wiki/Rounding[/URL] for details on the methods --Kyle ------------- Using this array in several languages: [-5.0, -4.5, -4.0, -3.5, -3.0, -2.5, -2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5] rounded: ruby [-5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5] gcc [-5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5] vbs (ugly but I had it on hand) [-5, -4, -4, -4, -3, -2, -2, -2, -1, 0, 0, 0, 1, 2, 2, 2, 3, 4, 4, 4] vb.net (again ugly, but on hand) [-5, -4, -4, -4, -3, -2, -2, -2, -1, 0, 0, 0, 1, 2, 2, 2, 3, 4, 4, 4] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
ruby rounding?
Top