class NumRu::Units::PowNode
Attributes
lhs[R]
power[R]
rhs[R]
Public Class Methods
new(lhs, rhs)
click to toggle source
# File lib/numru/units.rb, line 2389 def initialize(lhs, rhs) @lhs, @rhs = lhs, rhs raise TypeError unless NumberNode === @rhs end
Public Instance Methods
factor()
click to toggle source
# File lib/numru/units.rb, line 2478 def factor Units::pow_f(@lhs.factor, @rhs.value) end
flatten2()
click to toggle source
# File lib/numru/units.rb, line 2421 def flatten2 x = @lhs.flatten2 case x when NumberNode a = @lhs.pow_eval(@rhs) when TerminalNode a = self when PowNode a = PowNode.new(x.lhs, x.rhs.mul_eval(@rhs)) when MulNode, MultiNode a = MultiNode.new() for gc in x a.append(gc.pow_eval(@rhs)) end else raise "internal error" end return a end
mul_eval(another)
click to toggle source
# File lib/numru/units.rb, line 2459 def mul_eval(another) raise "internal error (#{name}, #{another.name})" if name != another.name case @lhs when NumberNode NumberNode.new(Units::pow_f(@lhs.value, @rhs.value) * another.value) else self.class.new(@lhs, @rhs.add_eval(another.power)) end end
name()
click to toggle source
# File lib/numru/units.rb, line 2441 def name case @lhs when NumberNode, NameNode @lhs.name else raise "internal error" end end
pow_eval(other)
click to toggle source
Calls superclass method
NumRu::Units::Node#pow_eval
# File lib/numru/units.rb, line 2412 def pow_eval(other) case other when NumberNode PowNode.new(@lhs, @rhs.mul_eval(other)) else super(other) end end
sort()
click to toggle source
# File lib/numru/units.rb, line 2469 def sort case @lhs when NumberNode NumberNode.new(Units::pow_f(@lhs.value, @rhs.value)) else self end end
to_s()
click to toggle source
# File lib/numru/units.rb, line 2394 def to_s lhs = @lhs.to_s case lhs when /\d$/, /[\d\.]/ lhs = "(#{lhs})" end rhs = @rhs.to_s if rhs == '1' lhs else rhs = "^(#{rhs})" if (/\./ =~ rhs) lhs + rhs end end
value()
click to toggle source
# File lib/numru/units.rb, line 2450 def value case @lhs when NumberNode Units::pow_f(@lhs.value, @rhs.value) else raise(format('%s#value: internal error', self.class.to_s)) end end