To the power of ...

Pixilang programming language
Post Reply
philipbergwerf
Posts: 174
Joined: Sat Mar 17, 2018 4:23 pm

To the power of ...

Post by philipbergwerf »

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?
philipbergwerf
Posts: 174
Joined: Sat Mar 17, 2018 4:23 pm

Re: To the power of ...

Post by philipbergwerf »

I found a solution:

Code: Select all

fn power($x, $y)
{  
    $i = 0
    $n = 1
    while $i < $y
    {
        $n = $x * $n
        $i + 1
    }
    ret($n)
}
$x to the power of $y
philipbergwerf
Posts: 174
Joined: Sat Mar 17, 2018 4:23 pm

Re: To the power of ...

Post by philipbergwerf »

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:

Code: Select all

$freq = 440 * 2^notesawayfroma440/12
So the exp of pow is a float.
Last edited by philipbergwerf on Fri Jul 09, 2021 4:18 pm, edited 1 time in total.
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: To the power of ...

Post by NightRadio »

pow(x,y)
You can check the full list in the math.h library of C/C++
Post Reply