Exponentiation operator: Difference between revisions

added Arturo
No edit summary
(added Arturo)
Line 418:
exponentiationOperatorTask(2.5, 10) --> {operator:9536.7431640625, |handler|:9536.7431640625}
exponentiationOperatorTask(2.5, -10) --> {operator:1.048576E-4, |handler|:1.048576E-4}</syntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">myPow: function [base,xp][
if xp < 0 [
(floating? base)? -> return 1 // myPow base neg xp
-> return 1 / myPow base neg xp
]
 
if xp = 0 ->
return 1
 
ans: 1
while [xp > 0][
ans: ans * base
xp: xp - 1
]
return ans
]
 
print ["2 ^ 3 =" myPow 2 3]
print ["1 ^ -10 =" myPow 1 neg 10]
print ["-1 ^ -3 =" myPow neg 1 neg 3]
print ""
print ["2.0 ^ -3 =" myPow 2.0 neg 3]
print ["1.5 ^ 0 =" myPow 1.5 0]
print ["4.5 ^ 2 =" myPow 4.5 2]</syntaxhighlight>
 
{{out}}
 
<pre>2 ^ 3 = 8
1 ^ -10 = 1
-1 ^ -3 = -1
 
2.0 ^ -3 = 0.125
1.5 ^ 0 = 1
4.5 ^ 2 = 20.25</pre>
 
=={{header|AutoHotkey}}==
1,532

edits