module SQLite3ExtendFunction::Functions::Power

SQLite3ExtendFunction::Functions::Power

Public Class Methods

call(a, b) click to toggle source

@param [Integer, Float] a @param [Integer, Float] b @return [Integer, Float] @raise [SQLite3::SQLException]

# File lib/sqlite3_extend_function/functions/power.rb, line 12
def call(a, b)
  return if a.nil? || b.nil?

  result = Float(a)**Float(b)
  result.to_i == result ? result.to_i : result
rescue ArgumentError
  raise SQLite3::SQLException, 'invalid input syntax for type double precision'
end