RE: Behaviour of round changed?
Andy Jones <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <[email protected]> |
IIRC it’s just round. A decision was made to round to the nearest even number in case of a tie, rather than to round down. This is the more standard approach? I think this is the relevant issue: https://bugs.ruby-lang.org/issues/12548 From: ruby-talk [mailto:[email protected]] On Behalf Of Peter Hickman Sent: 08 January 2019 13:15 To: ruby-talk ML Subject: Behaviour of round changed? I am moving some algorithms between 1.9.3 and 2.4.2 and found (after much head scratching) 2.4.2 :001 > 1.015.round(2) => 1.02 1.9.3-p551 :001 > 1.015.round(2) => 1.01 We are calculating margin prices and round input values to 2 places because the precision is not needed and it can help with caching The tests broke :( Let me see if I understand this, Ruby has changed how basic maths functions work Can I trust ceil, floor, truncate or any of the other number related functions? Do I need to write tests for the language itself for when I upgrade to a newer version in the future or should I stick with 1.9.3 for all eternity? A change at this low a level is almost impossible to speculatively test for, if I cannot trust the language I am using I cannot trust my code at all I am now in a position of having to test my code to an excessive degree because I cannot trust there are not any other changes that will be triggered on some previously innocent edge case I am extremely pissed off right now Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer> Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data. Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>