Class: Integer

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



1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
# File 'lib/nio/fmt.rb', line 1673

def self.nio_read_neutral(neutral)   
  x = nil
  
  if neutral.special?
    raise Nio::InvalidFormat,"Invalid integer numeral"
  elsif neutral.rep_pos<neutral.digits.length  
    return Rational.nio_read_neutral(neutral).to_i
  else
    digits = neutral.digits
    
    if neutral.dec_pos <= 0
      digits = '0'
    elsif neutral.dec_pos <= digits.length
      digits = digits[0...neutral.dec_pos]
    else
      digits = digits + '0'*(neutral.dec_pos-digits.length)  
    end
    
    x = digits.to_i(neutral.base)
  # this was formely needed because we didn't adust the digits
  #  if neutral.dec_pos != neutral.digits.length
  #    # with rational included, negative powers of ten are rational numbers
  #    x = (x*((neutral.base)**(neutral.dec_pos-neutral.digits.length))).to_i   
  #  end
    x = -x if neutral.sign=='-'
  end
   
  return x
end

Instance Method Details

#nio_write_neutral(fmt) ⇒ Object



1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
# File 'lib/nio/fmt.rb', line 1702

def nio_write_neutral(fmt)
  neutral = Nio::NeutralNum.new
  x = self
  
  sign = x<0 ? '-' : '+'
  txt = x.abs.to_s(fmt.get_base)
  dec_pos = rep_pos = txt.length  
  neutral.set sign, txt, dec_pos, nil, fmt.get_base_digits, false ,fmt.get_round
       
  return neutral
end

#nio_xrObject



83
84
85
# File 'lib/nio/rtnlzr.rb', line 83

def nio_xr
  return Rational(self,1)
end