* [ruby-core:50269] [ruby-trunk - Bug #7458][Open] Depending on value of BigDecimal::limit, addition can give inaccurate results
@ 2012-11-28 20:21 bpow (Bradford Powell)
2013-02-18 15:35 ` [ruby-core:52476] [ruby-trunk - Bug #7458] " mame (Yusuke Endoh)
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: bpow (Bradford Powell) @ 2012-11-28 20:21 UTC (permalink / raw
To: ruby-core
Issue #7458 has been reported by bpow (Bradford Powell).
----------------------------------------
Bug #7458: Depending on value of BigDecimal::limit, addition can give inaccurate results
https://bugs.ruby-lang.org/issues/7458
Author: bpow (Bradford Powell)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 2.0.0dev
=begin
This bug is present in ruby-trunk and also in 1.8.7 and 1.9.3p125.
I apologize that I cannot figure out what exactly is going wrong and how to patch, but at least I have a small reproducible test case.
When adding very small numbers (like 7E-19) to 1, the result should be very close to 1. However, depending on the limit to BigDecimal's precision, this is not always what is resulted, as this script demonstrates:
require 'bigdecimal'
one = BigDecimal('1')
smallnum = BigDecimal('7E-19')
0.upto(20) do |lim|
BigDecimal::limit(lim)
result = one + smallnum
puts "result is #{result}, as float is #{result.to_f} with limit #{lim}"
end
When run in trunk (or 1.8.7), the results it gives are:
result is 0.10000000000000000007E1, as float is 1.0 with limit 0
result is 0.1E1, as float is 1.0 with limit 1
result is 0.1E1, as float is 1.0 with limit 2
result is 0.1E1, as float is 1.0 with limit 3
result is 0.1E1, as float is 1.0 with limit 4
result is 0.1E1, as float is 1.0 with limit 5
result is 0.1E1, as float is 1.0 with limit 6
result is 0.1E1, as float is 1.0 with limit 7
result is 0.1E1, as float is 1.0 with limit 8
result is 0.1E1, as float is 1.0 with limit 9
result is 0.2E1, as float is 2.0 with limit 10
result is 0.2E1, as float is 2.0 with limit 11
result is 0.2E1, as float is 2.0 with limit 12
result is 0.2E1, as float is 2.0 with limit 13
result is 0.2E1, as float is 2.0 with limit 14
result is 0.2E1, as float is 2.0 with limit 15
result is 0.2E1, as float is 2.0 with limit 16
result is 0.2E1, as float is 2.0 with limit 17
result is 0.2E1, as float is 2.0 with limit 18
result is 0.1000000000000000001E1, as float is 1.0 with limit 19
result is 0.10000000000000000007E1, as float is 1.0 with limit 20
So the results with limit <=9 or >=19 are as expected, but in between the result returned is equal to 2.0
A test that demonstrates this (suitable for inclusion in (({test/bigdecimal/test_bigdecimal.rb})) is:
def test_limited_one_plus_small
one = BigDecimal('1')
smallnum = BigDecimal('0.7E-18')
BigDecimal::save_limit do
1.upto(20) do |lim|
BigDecimal::limit(lim)
result = (one + smallnum).to_f.to_s
assert_equal("1.0", result, "Error adding a small number to one with BigDecimal::limit(#{lim})")
end
end
end
I think this is different from #7404 (from what I can tell by google translate), but I apologize for the duplicate if not.
=end
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:52476] [ruby-trunk - Bug #7458] Depending on value of BigDecimal::limit, addition can give inaccurate results
2012-11-28 20:21 [ruby-core:50269] [ruby-trunk - Bug #7458][Open] Depending on value of BigDecimal::limit, addition can give inaccurate results bpow (Bradford Powell)
@ 2013-02-18 15:35 ` mame (Yusuke Endoh)
2013-10-11 1:18 ` [ruby-core:57819] " bpow (Bradford Powell)
2013-12-12 17:08 ` [ruby-core:59075] [ruby-trunk - Bug #7458][Closed] " mrkn (Kenta Murata)
2 siblings, 0 replies; 4+ messages in thread
From: mame (Yusuke Endoh) @ 2013-02-18 15:35 UTC (permalink / raw
To: ruby-core
Issue #7458 has been updated by mame (Yusuke Endoh).
Target version changed from 2.0.0 to next minor
----------------------------------------
Bug #7458: Depending on value of BigDecimal::limit, addition can give inaccurate results
https://bugs.ruby-lang.org/issues/7458#change-36546
Author: bpow (Bradford Powell)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: ext
Target version: next minor
ruby -v: 2.0.0dev
=begin
This bug is present in ruby-trunk and also in 1.8.7 and 1.9.3p125.
I apologize that I cannot figure out what exactly is going wrong and how to patch, but at least I have a small reproducible test case.
When adding very small numbers (like 7E-19) to 1, the result should be very close to 1. However, depending on the limit to BigDecimal's precision, this is not always what is resulted, as this script demonstrates:
require 'bigdecimal'
one = BigDecimal('1')
smallnum = BigDecimal('7E-19')
0.upto(20) do |lim|
BigDecimal::limit(lim)
result = one + smallnum
puts "result is #{result}, as float is #{result.to_f} with limit #{lim}"
end
When run in trunk (or 1.8.7), the results it gives are:
result is 0.10000000000000000007E1, as float is 1.0 with limit 0
result is 0.1E1, as float is 1.0 with limit 1
result is 0.1E1, as float is 1.0 with limit 2
result is 0.1E1, as float is 1.0 with limit 3
result is 0.1E1, as float is 1.0 with limit 4
result is 0.1E1, as float is 1.0 with limit 5
result is 0.1E1, as float is 1.0 with limit 6
result is 0.1E1, as float is 1.0 with limit 7
result is 0.1E1, as float is 1.0 with limit 8
result is 0.1E1, as float is 1.0 with limit 9
result is 0.2E1, as float is 2.0 with limit 10
result is 0.2E1, as float is 2.0 with limit 11
result is 0.2E1, as float is 2.0 with limit 12
result is 0.2E1, as float is 2.0 with limit 13
result is 0.2E1, as float is 2.0 with limit 14
result is 0.2E1, as float is 2.0 with limit 15
result is 0.2E1, as float is 2.0 with limit 16
result is 0.2E1, as float is 2.0 with limit 17
result is 0.2E1, as float is 2.0 with limit 18
result is 0.1000000000000000001E1, as float is 1.0 with limit 19
result is 0.10000000000000000007E1, as float is 1.0 with limit 20
So the results with limit <=9 or >=19 are as expected, but in between the result returned is equal to 2.0
A test that demonstrates this (suitable for inclusion in (({test/bigdecimal/test_bigdecimal.rb})) is:
def test_limited_one_plus_small
one = BigDecimal('1')
smallnum = BigDecimal('0.7E-18')
BigDecimal::save_limit do
1.upto(20) do |lim|
BigDecimal::limit(lim)
result = (one + smallnum).to_f.to_s
assert_equal("1.0", result, "Error adding a small number to one with BigDecimal::limit(#{lim})")
end
end
end
I think this is different from #7404 (from what I can tell by google translate), but I apologize for the duplicate if not.
=end
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:57819] [ruby-trunk - Bug #7458] Depending on value of BigDecimal::limit, addition can give inaccurate results
2012-11-28 20:21 [ruby-core:50269] [ruby-trunk - Bug #7458][Open] Depending on value of BigDecimal::limit, addition can give inaccurate results bpow (Bradford Powell)
2013-02-18 15:35 ` [ruby-core:52476] [ruby-trunk - Bug #7458] " mame (Yusuke Endoh)
@ 2013-10-11 1:18 ` bpow (Bradford Powell)
2013-12-12 17:08 ` [ruby-core:59075] [ruby-trunk - Bug #7458][Closed] " mrkn (Kenta Murata)
2 siblings, 0 replies; 4+ messages in thread
From: bpow (Bradford Powell) @ 2013-10-11 1:18 UTC (permalink / raw
To: ruby-core
Issue #7458 has been updated by bpow (Bradford Powell).
=begin
Still present in
(({ruby 2.1.0dev (2013-09-22 trunk 43011) [x86_64-linux]}))
=end
----------------------------------------
Bug #7458: Depending on value of BigDecimal::limit, addition can give inaccurate results
https://bugs.ruby-lang.org/issues/7458#change-42421
Author: bpow (Bradford Powell)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: ext
Target version: next minor
ruby -v: 2.0.0dev
Backport:
=begin
This bug is present in ruby-trunk and also in 1.8.7 and 1.9.3p125.
I apologize that I cannot figure out what exactly is going wrong and how to patch, but at least I have a small reproducible test case.
When adding very small numbers (like 7E-19) to 1, the result should be very close to 1. However, depending on the limit to BigDecimal's precision, this is not always what is resulted, as this script demonstrates:
require 'bigdecimal'
one = BigDecimal('1')
smallnum = BigDecimal('7E-19')
0.upto(20) do |lim|
BigDecimal::limit(lim)
result = one + smallnum
puts "result is #{result}, as float is #{result.to_f} with limit #{lim}"
end
When run in trunk (or 1.8.7), the results it gives are:
result is 0.10000000000000000007E1, as float is 1.0 with limit 0
result is 0.1E1, as float is 1.0 with limit 1
result is 0.1E1, as float is 1.0 with limit 2
result is 0.1E1, as float is 1.0 with limit 3
result is 0.1E1, as float is 1.0 with limit 4
result is 0.1E1, as float is 1.0 with limit 5
result is 0.1E1, as float is 1.0 with limit 6
result is 0.1E1, as float is 1.0 with limit 7
result is 0.1E1, as float is 1.0 with limit 8
result is 0.1E1, as float is 1.0 with limit 9
result is 0.2E1, as float is 2.0 with limit 10
result is 0.2E1, as float is 2.0 with limit 11
result is 0.2E1, as float is 2.0 with limit 12
result is 0.2E1, as float is 2.0 with limit 13
result is 0.2E1, as float is 2.0 with limit 14
result is 0.2E1, as float is 2.0 with limit 15
result is 0.2E1, as float is 2.0 with limit 16
result is 0.2E1, as float is 2.0 with limit 17
result is 0.2E1, as float is 2.0 with limit 18
result is 0.1000000000000000001E1, as float is 1.0 with limit 19
result is 0.10000000000000000007E1, as float is 1.0 with limit 20
So the results with limit <=9 or >=19 are as expected, but in between the result returned is equal to 2.0
A test that demonstrates this (suitable for inclusion in (({test/bigdecimal/test_bigdecimal.rb})) is:
def test_limited_one_plus_small
one = BigDecimal('1')
smallnum = BigDecimal('0.7E-18')
BigDecimal::save_limit do
1.upto(20) do |lim|
BigDecimal::limit(lim)
result = (one + smallnum).to_f.to_s
assert_equal("1.0", result, "Error adding a small number to one with BigDecimal::limit(#{lim})")
end
end
end
I think this is different from #7404 (from what I can tell by google translate), but I apologize for the duplicate if not.
=end
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:59075] [ruby-trunk - Bug #7458][Closed] Depending on value of BigDecimal::limit, addition can give inaccurate results
2012-11-28 20:21 [ruby-core:50269] [ruby-trunk - Bug #7458][Open] Depending on value of BigDecimal::limit, addition can give inaccurate results bpow (Bradford Powell)
2013-02-18 15:35 ` [ruby-core:52476] [ruby-trunk - Bug #7458] " mame (Yusuke Endoh)
2013-10-11 1:18 ` [ruby-core:57819] " bpow (Bradford Powell)
@ 2013-12-12 17:08 ` mrkn (Kenta Murata)
2 siblings, 0 replies; 4+ messages in thread
From: mrkn (Kenta Murata) @ 2013-12-12 17:08 UTC (permalink / raw
To: ruby-core
Issue #7458 has been updated by mrkn (Kenta Murata).
Status changed from Assigned to Closed
I've fix this issue in r44153.
----------------------------------------
Bug #7458: Depending on value of BigDecimal::limit, addition can give inaccurate results
https://bugs.ruby-lang.org/issues/7458#change-43628
Author: bpow (Bradford Powell)
Status: Closed
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: ext
Target version: next minor
ruby -v: 2.0.0dev
Backport:
=begin
This bug is present in ruby-trunk and also in 1.8.7 and 1.9.3p125.
I apologize that I cannot figure out what exactly is going wrong and how to patch, but at least I have a small reproducible test case.
When adding very small numbers (like 7E-19) to 1, the result should be very close to 1. However, depending on the limit to BigDecimal's precision, this is not always what is resulted, as this script demonstrates:
require 'bigdecimal'
one = BigDecimal('1')
smallnum = BigDecimal('7E-19')
0.upto(20) do |lim|
BigDecimal::limit(lim)
result = one + smallnum
puts "result is #{result}, as float is #{result.to_f} with limit #{lim}"
end
When run in trunk (or 1.8.7), the results it gives are:
result is 0.10000000000000000007E1, as float is 1.0 with limit 0
result is 0.1E1, as float is 1.0 with limit 1
result is 0.1E1, as float is 1.0 with limit 2
result is 0.1E1, as float is 1.0 with limit 3
result is 0.1E1, as float is 1.0 with limit 4
result is 0.1E1, as float is 1.0 with limit 5
result is 0.1E1, as float is 1.0 with limit 6
result is 0.1E1, as float is 1.0 with limit 7
result is 0.1E1, as float is 1.0 with limit 8
result is 0.1E1, as float is 1.0 with limit 9
result is 0.2E1, as float is 2.0 with limit 10
result is 0.2E1, as float is 2.0 with limit 11
result is 0.2E1, as float is 2.0 with limit 12
result is 0.2E1, as float is 2.0 with limit 13
result is 0.2E1, as float is 2.0 with limit 14
result is 0.2E1, as float is 2.0 with limit 15
result is 0.2E1, as float is 2.0 with limit 16
result is 0.2E1, as float is 2.0 with limit 17
result is 0.2E1, as float is 2.0 with limit 18
result is 0.1000000000000000001E1, as float is 1.0 with limit 19
result is 0.10000000000000000007E1, as float is 1.0 with limit 20
So the results with limit <=9 or >=19 are as expected, but in between the result returned is equal to 2.0
A test that demonstrates this (suitable for inclusion in (({test/bigdecimal/test_bigdecimal.rb})) is:
def test_limited_one_plus_small
one = BigDecimal('1')
smallnum = BigDecimal('0.7E-18')
BigDecimal::save_limit do
1.upto(20) do |lim|
BigDecimal::limit(lim)
result = (one + smallnum).to_f.to_s
assert_equal("1.0", result, "Error adding a small number to one with BigDecimal::limit(#{lim})")
end
end
end
I think this is different from #7404 (from what I can tell by google translate), but I apologize for the duplicate if not.
=end
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-12 17:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-28 20:21 [ruby-core:50269] [ruby-trunk - Bug #7458][Open] Depending on value of BigDecimal::limit, addition can give inaccurate results bpow (Bradford Powell)
2013-02-18 15:35 ` [ruby-core:52476] [ruby-trunk - Bug #7458] " mame (Yusuke Endoh)
2013-10-11 1:18 ` [ruby-core:57819] " bpow (Bradford Powell)
2013-12-12 17:08 ` [ruby-core:59075] [ruby-trunk - Bug #7458][Closed] " mrkn (Kenta Murata)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).