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



1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
# File 'lib/nio/fmt.rb', line 1717

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



1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
# File 'lib/nio/fmt.rb', line 1733

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