In excel I can get 'to the power of' using '^'. What is the equivalent in pixilang?
Example:5^3 = 5 × 5 × 5 = 125
Is there a function that does this?
To the power of ...
-
- Posts: 174
- Joined: Sat Mar 17, 2018 4:23 pm
Re: To the power of ...
I found a solution:
$x to the power of $y
Code: Select all
fn power($x, $y)
{
$i = 0
$n = 1
while $i < $y
{
$n = $x * $n
$i + 1
}
ret($n)
}
-
- Posts: 174
- Joined: Sat Mar 17, 2018 4:23 pm
Re: To the power of ...
I still don't know the real answer. The function i posted works well on integers but float doesn't work. How to calculate x to the power of y in pixilang?
I need to calculate:
So the exp of pow is a float.
I need to calculate:
Code: Select all
$freq = 440 * 2^notesawayfroma440/12
Last edited by philipbergwerf on Fri Jul 09, 2021 4:18 pm, edited 1 time in total.
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: To the power of ...
pow(x,y)
You can check the full list in the math.h library of C/C++
You can check the full list in the math.h library of C/C++