class IluzioCalculator::Calculator
Public Instance Methods
add(x, y)
click to toggle source
BASIC OPERATIONS
# File lib/iluzio_calculator/calculator.rb, line 15 def add(x, y) operandControl(x, y) return x + y end
cbrt(x)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 56 def cbrt(x) operandControl(x) return Math.cbrt(x) end
divide(x, y)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 30 def divide(x, y) operandControl(x, y) raise ZeroDivisionError unless y != 0 return x / y end
log(x, y)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 67 def log(x, y) operandControl(x, y) return Math.log(x, y) end
mod(x, y)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 36 def mod(x, y) operandControl(x, y) return x % y end
multiply(x, y)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 25 def multiply(x, y) operandControl(x, y) return x * y end
nthroot(x, y)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 61 def nthroot(x, y) operandControl(x, y) raise RootNegativeError unless x >= 0 || y % 2 != 0 return (x ** (y ** -1)) end
pow(x, y)
click to toggle source
COMPLEX OPERATIONS
# File lib/iluzio_calculator/calculator.rb, line 45 def pow(x, y) operandControl(x, y) return x ** y end
sqrt(x)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 50 def sqrt(x) operandControl(x) raise RootNegativeError unless x >= 0 return Math.sqrt(x) end
subtract(x, y)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 20 def subtract(x, y) operandControl(x, y) return x - y end
Private Instance Methods
operandControl(*x)
click to toggle source
# File lib/iluzio_calculator/calculator.rb, line 5 def operandControl(*x) x.each { |number| raise OperandNumericError unless number.is_a? Numeric} end