Class: Rational

Inherits:
Object
  • Object
show all
Includes:
Nio::Formattable
Defined in:
lib/nio/fmt.rb,
lib/nio/rtnlzr.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Nio::Formattable

append_features, #nio_round, #nio_write

Class Method Details

.nio_read_neutral(neutral) ⇒ Object



1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
# File 'lib/nio/fmt.rb', line 1751

def self.nio_read_neutral(neutral)   
  x = nil
  
  if neutral.special?
    case neutral.special
      when :nan
        x = Rational(0,0)
      when :inf
        x = Rational((neutral.sign=='-' ? -1 : +1),0)
    end
  else
    x = Rational(*neutral.to_RepDec.getQ)
  end
   
  return x
end

Instance Method Details

#nio_num_denObject

helper method to return both the numerator and denominator



95
96
97
# File 'lib/nio/rtnlzr.rb', line 95

def nio_num_den
  return [numerator,denominator]
end

#nio_write_neutral(fmt) ⇒ Object



1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
# File 'lib/nio/fmt.rb', line 1767

def nio_write_neutral(fmt)
  neutral = Nio::NeutralNum.new
  x = self
  
  if x.denominator==0
    if x.numerator>0    
      neutral.set_special(:inf)
    elsif x.numerator<0
      neutral.set_special(:inf,'-')
    else
      neutral.set_special(:nan)
    end
  else
    if fmt.get_base==10
      rd = Nio::RepDec.new.setQ(x.numerator,x.denominator)
    else
      opt = Nio::RepDec::DEF_OPT.dup.set_digits(fmt.get_base_digits)
      rd = Nio::RepDec.new.setQ(x.numerator,x.denominator, opt)
    end
    neutral = rd.to_NeutralNum(fmt.get_base_digits)
    neutral.rounding = fmt.get_round
  end
       
  return neutral
end

#nio_xrObject



90
91
92
# File 'lib/nio/rtnlzr.rb', line 90

def nio_xr
  return self
end