Re: Behaviour of round changed?
Matthew Kerwin <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CACweHNCX1e-GcQNDROB54RB-5Zu3sobWNoW8PReMA=RSPuARWw@mail.gmail.com> |
It's late here, so I can only be quick:
1. Don't ever use floats for money.
2. It was documented in the release notes for 2.4.0
<https://docs.ruby-lang.org/en/2.4.0/NEWS.html>
"Float#round now takes an optional keyword argument, half option,
and the default behavior is round-to-nearest-even now. [Bug #12548]"
3. See these tickets in the bug tracker for some history on the #round changes:
* https://bugs.ruby-lang.org/issues/12548
* https://bugs.ruby-lang.org/issues/12958
* https://bugs.ruby-lang.org/issues/12953
4. Even Ruby 2.4 is old now; 2.6.0 has been released...
5. Don't ever use floats for money.
Cheers
On Tue, 8 Jan 2019 at 23:17, Peter Hickman
<[email protected]> wrote:
>
> 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
>
>
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
Matthew Kerwin
https://matthew.kerwin.net.au/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>