From: shyouhei@... Date: 2016-02-22T01:28:34+00:00 Subject: [ruby-core:73917] [Ruby trunk Bug#12039] Fixnum#infinite?/Bignum#infinite or Numeric#infinte, consistent with Float#infinite? and BigDecimal#infinite? Issue #12039 has been updated by Shyouhei Urabe. Another real-world use-case where I found Numeric#infinite? useful is JSON validation. Infinities are not allowed in JSON so a programmer want to filter them out before converting a Numeric into JSON, but that is not straight-forward right now. With this method it becomes much OO-ish. ---------------------------------------- Bug #12039: Fixnum#infinite?/Bignum#infinite or Numeric#infinte, consistent with Float#infinite? and BigDecimal#infinite? https://bugs.ruby-lang.org/issues/12039#change-57073 * Author: Samuel Williams * Status: Open * Priority: Normal * Assignee: * ruby -v: * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- We have an issue where it is not easy to ask if a number is +ve or -ve infinity. https://github.com/rails/arel/issues/411 Both Float and BigDecimal do respond to infinite? but Integer derivatives don't. It sort of makes sense, since we don't have an infinity value for Fixnum/Bignum. However, it makes polymorphic code hard. ``` [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 ``` Given a Numeric value x, it would be nice to query if it is INFINITY or not. Propose adding a default implementation to Numeric, which always returns false or nil. -- https://bugs.ruby-lang.org/ Unsubscribe: