diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-05 09:49:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-05 09:49:39 +0000 |
commit | dfe91fcd08e7e255b5cb1b306e53bea1ddb54e5f (patch) | |
tree | d209f0b546e45cb8d8fa7fc2bbbb5044e53e2c8f /lib/rexml/functions.rb | |
parent | 76977611dd68e384fdce8c546efda5e1931e67a6 (diff) | |
download | ruby-dfe91fcd08e7e255b5cb1b306e53bea1ddb54e5f.tar.gz |
numeric.c: round to nearest even
* numeric.c (flo_round, int_round): support round-to-nearest-even
semantics of IEEE 754 to match sprintf behavior, and add `half:`
optional keyword argument for the old behavior.
[ruby-core:76273] [Bug #12548]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/functions.rb')
-rw-r--r-- | lib/rexml/functions.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index ee73b28881..b56103d4f2 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -205,8 +205,8 @@ module REXML # Now, get the bounds. The XPath bounds are 1..length; the ruby bounds # are 0..length. Therefore, we have to offset the bounds by one. - ruby_start = ruby_start.round - 1 - ruby_length = ruby_length.round + ruby_start = round(ruby_start) - 1 + ruby_length = round(ruby_length) if ruby_start < 0 ruby_length += ruby_start unless infinite_length @@ -376,10 +376,13 @@ module REXML end def Functions::round( number ) + number = number(number) begin - number(number).round + neg = number.negative? + number = number.abs.round(half: :up) + neg ? -number : number rescue FloatDomainError - number(number) + number end end |