[#23231] What do you think about changing the return value of Kernel#require and Kernel#load to the source encoding of the required file? — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Dear Ruby developers and users!

8 messages 2009/04/17

[#23318] [Feature #1408] 0.1.to_r not equal to (1/10) — Heesob Park <redmine@...>

Feature #1408: 0.1.to_r not equal to (1/10)

19 messages 2009/04/26

[ruby-core:23286] [Bug #1397] to_f of rational

From: Karl Brodowsky <redmine@...>
Date: 2009-04-22 10:39:57 UTC
List: ruby-core #23286
Issue #1397 has been updated by Karl Brodowsky.


A fix for this bug might be along the following line, but this might still cause rounding errors in case only one of numerator and denominator is above Float::MAX and the other one is pretty small and would loose significant digits.


class Rational

  FLOAT_MAX_I = Float::MAX.to_i

  def to_f
    numerator   = @numerator
    denominator = @denominator
    sign        = numerator <=> 0
    if (sign.zero?)
      return 0.0
    elsif sign < 0
      numerator = -numerator
    end
    while numerator >= FLOAT_MAX_I || denominator >=
FLOAT_MAX_I do
      numerator   >>= 8
      denominator >>= 8
      if (denominator == 0)
        raise ZeroDivisionError, "denominator too close to
zero: #{@numerator}/{@denominator}"
      elsif numerator == 0
        return 0.0
      end
    end
    return numerator.to_f / denominator.to_f
  end
end

----------------------------------------
http://redmine.ruby-lang.org/issues/show/1397

----------------------------------------
http://redmine.ruby-lang.org

In This Thread

Prev Next