class Keisan::AST::Number
Attributes
number[R]
Public Class Methods
new(number)
click to toggle source
# File lib/keisan/ast/number.rb, line 6 def initialize(number) @number = number # Reduce the number if possible case @number when Rational @number = @number.numerator if @number.denominator == 1 end end
Public Instance Methods
%(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#%
# File lib/keisan/ast/number.rb, line 75 def %(other) other = other.to_node case other when Number Number.new(value % other.value) else super end end
&(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#&
# File lib/keisan/ast/number.rb, line 85 def &(other) other = other.to_node case other when Number Number.new(value & other.value) else super end end
*(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#*
# File lib/keisan/ast/number.rb, line 45 def *(other) other = other.to_node case other when Number Number.new(value * other.value) else super end end
**(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#**
# File lib/keisan/ast/number.rb, line 65 def **(other) other = other.to_node case other when Number Number.new(value ** other.value) else super end end
+(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#+
# File lib/keisan/ast/number.rb, line 27 def +(other) other = other.to_node case other when Number Number.new(value + other.value) when Date Date.new(other.value + value) when Time Time.new(other.value + value) else super end end
+@()
click to toggle source
# File lib/keisan/ast/number.rb, line 23 def +@ Number.new(value) end
-(other)
click to toggle source
# File lib/keisan/ast/number.rb, line 41 def -(other) self + (-other.to_node) end
-@()
click to toggle source
# File lib/keisan/ast/number.rb, line 19 def -@ Number.new(-value) end
/(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#/
# File lib/keisan/ast/number.rb, line 55 def /(other) other = other.to_node case other when Number Number.new(Rational(value, other.value)) else super end end
<(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#<
# File lib/keisan/ast/number.rb, line 159 def <(other) other = other.to_node case other when Number Boolean.new(value < other.value) else super end end
<<(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#<<
# File lib/keisan/ast/number.rb, line 119 def <<(other) other = other.to_node case other when Number Number.new(value << other.value) else super end end
<=(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#<=
# File lib/keisan/ast/number.rb, line 169 def <=(other) other = other.to_node case other when Number Boolean.new(value <= other.value) else super end end
>(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#>
# File lib/keisan/ast/number.rb, line 139 def >(other) other = other.to_node case other when Number Boolean.new(value > other.value) else super end end
>=(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#>=
# File lib/keisan/ast/number.rb, line 149 def >=(other) other = other.to_node case other when Number Boolean.new(value >= other.value) else super end end
>>(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#>>
# File lib/keisan/ast/number.rb, line 129 def >>(other) other = other.to_node case other when Number Number.new(value >> other.value) else super end end
^(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#^
# File lib/keisan/ast/number.rb, line 99 def ^(other) other = other.to_node case other when Number Number.new(value ^ other.value) else super end end
differentiate(variable, context = nil)
click to toggle source
# File lib/keisan/ast/number.rb, line 210 def differentiate(variable, context = nil) 0.to_node end
equal(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#equal
# File lib/keisan/ast/number.rb, line 179 def equal(other) other = other.to_node case other when Number Boolean.new(value == other.value) else super end end
not_equal(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#not_equal
# File lib/keisan/ast/number.rb, line 189 def not_equal(other) other = other.to_node case other when Number Boolean.new(value != other.value) else super end end
simplify(context = nil)
click to toggle source
# File lib/keisan/ast/number.rb, line 199 def simplify(context = nil) case number when Rational if number.denominator == 1 @number = number.numerator end end self end
value(context = nil)
click to toggle source
# File lib/keisan/ast/number.rb, line 15 def value(context = nil) number end
|(other)
click to toggle source
Calls superclass method
Keisan::AST::ConstantLiteral#|
# File lib/keisan/ast/number.rb, line 109 def |(other) other = other.to_node case other when Number Number.new(value | other.value) else super end end
~()
click to toggle source
# File lib/keisan/ast/number.rb, line 95 def ~ Number.new(~value) end