[#92070] [Ruby trunk Feature#15667] Introduce malloc_trim(0) in full gc cycles — sam.saffron@...
Issue #15667 has been updated by sam.saffron (Sam Saffron).
3 messages
2019/04/01
[ruby-core:92267] [Ruby trunk Bug#12548] Rounding modes inconsistency between round versus sprintf
From:
jakub.suder@...
Date:
2019-04-13 00:46:40 UTC
List:
ruby-core #92267
Issue #12548 has been updated by mackuba (Kuba Suder).
I came across this thread now, because I've noticed that sprintf's behavior has actually changed in Ruby 2.4 too, just... not the same way as round's did...
```
> echo "n = [5.005, 5.015, 5.025]; puts 'round: ' + n.map { |x| x.round(2) }.join(' '); puts 'sprintf: ' + n.map { |x| sprintf('%.2f', x) }.join(' ')" > /tmp/floats.rb
> rvm 2.3.7 do ruby /tmp/floats.rb
round: 5.01 5.02 5.03
sprintf: 5.00 5.01 5.03
> rvm 2.4.0 do ruby /tmp/floats.rb
round: 5.01 5.02 5.03
sprintf: 5.00 5.02 5.02
```
----------------------------------------
Bug #12548: Rounding modes inconsistency between round versus sprintf
https://bugs.ruby-lang.org/issues/12548#change-77600
* Author: unclekiki (Kieran McCusker)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: 2.4.0
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Hi
I've found this possible bug with `sprintf` in our production code, but it
seems very odd that no one has reported it so I'm doubting myself.
I've tested a few versions (CRuby 2.3.1 and 2.1.9) and it was present in
both.
To reproduce in irb:
```ruby
sprintf('%1.0f', 12.5)
```
Expected result 13 actual 12
In fact if you look at the number sequence 0.5 -> 99.5 you find the even
half will all round down and the odd half round up. 12.5.round produces the correct result (13)
If you do the same in jruby 2.2.1 you get the expected result of 13.
Many thanks
Kieran
---Files--------------------------------
round_even.patch (4.43 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>