How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Lua programming language
How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Lua programming language
Table of Contents
Problem Statement
(Many programming languages, especially those with extended─precision integer arithmetic, usually support one of **, ^, ↑ or some such for exponentiation.)
Some languages treat/honor infix operators when performing exponentiation (raising numbers to some power by the language's exponentiation operator, if the computer programming language has one).
Other programming languages may make use of the POW or some other BIF (Built─In Ffunction), or some other library service. If your language's exponentiation operator is not one of the usual ones, please comment on how to recognize it.
This task will deal with the case where there is some form of an infix operator operating in (or operating on) the base.
A negative five raised to the 3rd power could be specified as:
(Not all computer programming languages have an exponential operator and/or support these syntax expression(s).
Try to present the results in the same format/manner as the other programming entries to make any differences apparent.
The variables may be of any type(s) that is/are applicable in your language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Lua programming language
Source code in the lua programming language
mathtype = math.type or type -- polyfill <5.3
function test(xs, ps)
for _,x in ipairs(xs) do
for _,p in ipairs(ps) do
print(string.format("%2.f %7s %2.f %7s %4.f %4.f %4.f %4.f", x, mathtype(x), p, mathtype(p), -x^p, -(x)^p, (-x)^p, -(x^p)))
end
end
end
print(" x type(x) p type(p) -x^p -(x)^p (-x)^p -(x^p)")
print("-- ------- -- ------- ------ ------ ------ ------")
test( {-5.,5.}, {2.,3.} ) -- "float" (or "number" if <5.3)
if math.type then -- if >=5.3
test( {-5,5}, {2,3} ) -- "integer"
end
You may also check:How to resolve the algorithm Simple windowed application step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Thiele's interpolation formula step by step in the zkl programming language
You may also check:How to resolve the algorithm Read a configuration file step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Determinant and permanent step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Determine if only one instance is running step by step in the FreeBASIC programming language