Methods

Class Index [+]

Quicksearch

When::Coordinates::Residue::Enumerator0

最良近似分数の系列を生成する Enumerator

Public Class Methods

new(*args) click to toggle source

オブジェクトの生成

  residue : When::Coordinates::Residue
  options : Hash
    :error       => Numeric
      収束とみなす誤差
    :count_limit => Integer
      最大繰り返し回数
     # File when/coordinates.rb, line 407
407:       def initialize(*args)
408:         residue = args[0]
409:         @x = residue.divisor * residue.carry + residue.remainder
410:         @y = residue.divisor
411:         super
412:         @error       = @options[:error]
413:         @count_limit = @options[:count_limit]
414:       end

Public Instance Methods

succ() click to toggle source

最良近似分数を生成する

returns : [remainder, divisor, error]

  remainder : Integer
    分子
  divisor   : Integer
    分母
  error     : Float
    誤差(系列は無限につづくので、使用する側で終了判定が必要)
     # File when/coordinates.rb, line 380
380:       def succ
381:         value = @current
382:         if (@z==@k) ||
383:            (@count_limit.kind_of?(Numeric) && @count >= @count_limit) ||
384:            (@error.kind_of?(Numeric) && @e && @error >= @e.abs)
385:           @current = nil
386:         else
387:           @z = 1.0/(@z-@k)
388:           @k = @z.floor
389:           @e = @p[1].to_f/@q[1]-@x.to_f/@y
390:           @current = [@p[1], @q[1], @e]
391:           @p = [@p[1], @p[1]*@k + @p[0]]
392:           @q = [@q[1], @q[1]*@k + @q[0]]
393:           @count += 1
394:         end
395:         return value
396:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.