Project

General

Profile

Actions

Bug #12414

closed

FloatDomainError in infinite Range#include? for certain BigDecimals

Added by RubyBugs (A Nonymous) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
[ruby-core:75682]

Description

What I did

require 'bigdecimal'

r = 0.04...(Float::INFINITY)
n = BigDecimal.new('0.13E0')
r.include?(n.to_f)
r.include?(n)

What I expected

true
true

What happens instead

true
FloatDomainError: Infinity
	from (irb):19:in `to_r'
	from (irb):19:in `<=>'
	from (irb):19:in `include?'
	from (irb):19
	from /Users/msiegel/.rvm/rubies/ruby-2.2.3/bin/irb:15:in `<main>'

Workaround

To workaround, I am calling #to_f on the BigDecimal before submitting it to the Range#include?

Note that this exception only occurs for certain BigDecimal values, not for all.


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #12417: warning: "isfinite" redefined when compiling bigdecimal.c on cygwinClosedshyouhei (Shyouhei Urabe)Actions
Is duplicate of Ruby master - Bug #10109: BigDecimal fail to compare to Float::INFINITYClosedmrkn (Kenta Murata)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0