class XPath::XPathNumber

Public Class Methods

new(num) click to toggle source
# File lib/xml/xpath.rb, line 685
def initialize(num)
  raise ::TypeError, "must be a Float" unless num.is_a? Float
  @value = num
end

Public Instance Methods

%(other) click to toggle source
# File lib/xml/xpath.rb, line 753
def %(other)
  n = other.to_f
  f = @value % n
  f = -f if @value < 0
  f = -f if n < 0
  @value = f
  self
end
*(other) click to toggle source
# File lib/xml/xpath.rb, line 743
def *(other)
  @value *= other.to_f
  self
end
+(other) click to toggle source
# File lib/xml/xpath.rb, line 733
def +(other)
  @value += other.to_f
  self
end
-(other) click to toggle source
# File lib/xml/xpath.rb, line 738
def -(other)
  @value -= other.to_f
  self
end
-@() click to toggle source
# File lib/xml/xpath.rb, line 762
def -@
  @value = -@value
  self
end
/(other) click to toggle source
# File lib/xml/xpath.rb, line 748
def /(other)
  @value /= other.to_f
  self
end
==(other) click to toggle source
# File lib/xml/xpath.rb, line 725
def ==(other)
  if other.is_a? XPathNodeSet or other.is_a? XPathBoolean then
    other == self
  else
    @value == other.to_f
  end
end
ceil() click to toggle source
# File lib/xml/xpath.rb, line 772
def ceil
  @value = @value.ceil.to_f
  self
end
floor() click to toggle source
# File lib/xml/xpath.rb, line 767
def floor
  @value = @value.floor.to_f
  self
end
round() click to toggle source
# File lib/xml/xpath.rb, line 777
def round
  f = @value
  unless f.nan? or f.infinite? then
    if f >= 0.0 then
      @value = f.round.to_f
    elsif f - f.truncate >= -0.5 then
      @value = f.ceil.to_f
    else
      @value = f.floor.to_f
    end
  end
  self
end
to_f() click to toggle source
# File lib/xml/xpath.rb, line 704
def to_f
  @value
end
to_number(context) click to toggle source
# File lib/xml/xpath.rb, line 720
def to_number(context)
  self
end
to_predicate() click to toggle source
# File lib/xml/xpath.rb, line 716
def to_predicate
  to_f
end
to_ruby() click to toggle source
# File lib/xml/xpath.rb, line 712
def to_ruby
  to_f
end
to_str() click to toggle source
# File lib/xml/xpath.rb, line 690
def to_str
  if @value.nan? then
    'NaN'
  elsif @value.infinite? then
    if @value < 0 then
      '-Infinity'
    else
      'Infinity'
    end
  else
    sprintf("%.100f", @value).gsub(/\.?0+\z/, '')    # enough?
  end
end
true?() click to toggle source
# File lib/xml/xpath.rb, line 708
def true?
  @value != 0.0 and not @value.nan?
end