forked from brynary/arel
-
Notifications
You must be signed in to change notification settings - Fork 388
Closed
Description
If you try to supply a range made from BigDecimal
values (e.g. provided by columns of type decimal), the code breaks.
Lines 27 to 45 in 63ea665
def between other | |
if equals_quoted?(other.begin, -Float::INFINITY) | |
if equals_quoted?(other.end, Float::INFINITY) | |
not_in([]) | |
elsif other.exclude_end? | |
lt(other.end) | |
else | |
lteq(other.end) | |
end | |
elsif equals_quoted?(other.end, Float::INFINITY) | |
gteq(other.begin) | |
elsif other.exclude_end? | |
gteq(other.begin).and(lt(other.end)) | |
else | |
left = quoted_node(other.begin) | |
right = quoted_node(other.end) | |
Nodes::Between.new(self, left.and(right)) | |
end | |
end |
It's because you can't compare BigDecimal with INFINITY
> BigDecimal.new(10) == Float::INFINITY
FloatDomainError: Infinity
from (pry):10:in `to_r'
The solution is not to use comparison but to use Float#infinite? and BigDecimal#infinite?
[13] pry(main)> Float::INFINITY.infinite?
=> 1
[14] pry(main)> -Float::INFINITY.infinite?
=> -1
[15] pry(main)> BigDecimal::INFINITY.infinite?
=> 1
[16] pry(main)> -BigDecimal::INFINITY.infinite?
=> -1
The problem this introduces is that it no longer works for Numeric values, e.g. Fixnum
and Bignum
. However, these can never be infinite.
Metadata
Metadata
Assignees
Labels
No labels