Most programming languages have a built-in implementation of exponentiation.



Task

Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition).

If the language supports operator (or procedure) overloading, then an overloaded form should be provided for both   intint   and   floatint   variants.



Related tasks

   Exponentiation order
   arbitrary-precision integers (included)
   Exponentiation with infix operators in (or operating on) the base


number = {}
 
function number.pow( a, b )
    local ret = 1
    if b >= 0 then
        for i = 1, b do
            ret = ret * a.val
        end
    else
        for i = b, -1 do
            ret = ret / a.val
        end
    end    
    return ret
end
 
function number.New( v )
    local num = { val = v }
    local mt = { __pow = number.pow }
    setmetatable( num, mt )
    return num
end
 
x = number.New( 5 )    
print( x^2 )                   --> 25
print( number.pow( x, -4 ) )   --> 0.016