Class: When::Coordinates::Residue::BestRationalApproximations
- Inherits:
-
Parts::Enumerator
- Object
- Enumerator
- Parts::Enumerator
- When::Coordinates::Residue::BestRationalApproximations
- Defined in:
- lib/when_exe/coordinates.rb
Overview
最良近似分数の系列を生成する Enumerator
Instance Attribute Summary
Attributes inherited from Parts::Enumerator
#count, #count_limit, #current, #direction, #exdate, #first, #index, #last, #object, #options, #parent, #processed
Instance Method Summary collapse
-
#_rewind ⇒ void
Enumerator の巻き戻し.
-
#initialize(parent, options = {}) ⇒ BestRationalApproximations
constructor
オブジェクトの生成.
-
#succ ⇒ Array<Numeric>
最良近似分数を生成する.
Methods inherited from Parts::Enumerator
_options, #each, #has_next?, #next, #with_index, #with_object
Constructor Details
#initialize(parent, options = {}) ⇒ BestRationalApproximations
オブジェクトの生成
530 531 532 533 534 535 536 |
# File 'lib/when_exe/coordinates.rb', line 530 def initialize(*args) @y = args[0].divisor @x = args[0].remainder + @y * args[0].carry super @error = @options[:error] || 1e-15 @count_limit = @options[:count_limit] end |
Instance Method Details
#_rewind ⇒ void
This method returns an undefined value.
Enumerator の巻き戻し
489 490 491 492 493 494 495 |
# File 'lib/when_exe/coordinates.rb', line 489 def _rewind @z = @x/@y @k = @z.floor @p = [1,@k] @q = [0, 1] super end |
#succ ⇒ Array<Numeric>
最良近似分数を生成する
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/when_exe/coordinates.rb', line 504 def succ value = @current if (@z==@k) || (@count_limit.kind_of?(Numeric) && @count >= @count_limit) || (@error.kind_of?(Numeric) && @e && @error >= @e.abs) @current = nil else @z = 1.0/(@z-@k) @k = @z.floor @e = @p[1].to_f/@q[1]-@x.to_f/@y @current = [@p[1], @q[1], @e] @p = [@p[1], @p[1]*@k + @p[0]] @q = [@q[1], @q[1]*@k + @q[0]] @count += 1 end return value end |