Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Exponentiation-operator/Lua/exponentiation-operator.lua
Normal file
26
Task/Exponentiation-operator/Lua/exponentiation-operator.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue