If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding premade modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
DSP code module and power (or root) function
8 posts
• Page 1 of 1
DSP code module and power (or root) function
It seems I'm missing something. I know that simple powers can be realized with simple multiplication (x * x for x^2, etc.). But without a power or root function, how would I go to realize this?
 Code: Select all
y = x^(1/x)
 tulamide
 Posts: 1811
 Joined: Sat Jun 21, 2014 2:48 pm
 Location: Germany
Re: DSP code module and power (or root) function
 Code: Select all
pow(base,exponent)
I'm not sure if it's missing from the manual. It might be...
 KG_is_back
 Posts: 1221
 Joined: Tue Oct 22, 2013 5:43 pm
 Location: Slovakia
Re: DSP code module and power (or root) function
Thanks a lot!
Yes, it is missing in the manual! Also, when looking at other people's codes, I never see this expression used. Instead, it's always worked around, similar to what I pointed to in the first post.
Yes, it is missing in the manual! Also, when looking at other people's codes, I never see this expression used. Instead, it's always worked around, similar to what I pointed to in the first post.
 tulamide
 Posts: 1811
 Joined: Sat Jun 21, 2014 2:48 pm
 Location: Germany
Re: DSP code module and power (or root) function
The pow funtion is quite cpu hungry though. Perhaps that´s also a reason for its scarce use.

martinvicanek  Posts: 846
 Joined: Sat Jun 22, 2013 8:28 pm
Re: DSP code module and power (or root) function
tulamide wrote:Thanks a lot!
Yes, it is missing in the manual! Also, when looking at other people's codes, I never see this expression used. Instead, it's always worked around, similar to what I pointed to in the first post.
martinvicanek wrote:The pow funtion is quite cpu hungry though. Perhaps that´s also a reason for its scarce use.
definitely... one would expect such a basic operation to be natively included in a CPU. Instead is is split into two operations 1. raising float to an integer and 2. y*2^x where x is in <01) range. So to calculate power you first need to multiply the exponent by is log2 then calculate its rounddown and modulo 1, do exponentiation by each of them and multiply the results. It can be done faster using SSE (2 orders of magnitude faster as seen in Martin's stream math functions) but the algorithm is pretty much the same.
In general you should avoid it like a plague if you care about speed, because it's pretty much guaranteed to be the bottleneck in your code...
 KG_is_back
 Posts: 1221
 Joined: Tue Oct 22, 2013 5:43 pm
 Location: Slovakia
Re: DSP code module and power (or root) function
KG_is_back wrote:In general you should avoid it like a plague if you care about speed, because it's pretty much guaranteed to be the bottleneck in your code...
The following introduction is not for KG or Martin, but for other people, who might read here and are not so much into math. KG, Martin, please head over to the last paragraph.
The function I wrote in the first post is called "inverse power function". A power function is pretty easy to understand. Just imagine the exponent tells you, how many times you have to multiply the base.
 Code: Select all
x^3 = x * x * x
Inverse power tells you the opposite. Let's put x = 2, to get comprehensible results.
 Code: Select all
x^(1/x) == 2^(1/2) == 2^0.5
Obviously we can't multiply x with itself just a half time. Instead it tells us that the result, we are looking for is the number, that multiplied with itself results in 2. And that is easy in this case. It's the square root of 2.
2√2 = 1,4142135623730950488016887242097
 Code: Select all
2^(1/2) == 2√2
x^(1/x) == x√x
Both, power and inverse power are building blocks in quite some DSP functions. So, I really wonder, do any of you know of a way to realize inverse power with just simple arithmetics? That's way over my head.
 tulamide
 Posts: 1811
 Joined: Sat Jun 21, 2014 2:48 pm
 Location: Germany
Re: DSP code module and power (or root) function
tulamide wrote: So, I really wonder, do any of you know of a way to realize inverse power with just simple arithmetics?
There is no closed form in terms of a finite number of elementary operations (+,,*,/) except for integer powers. In practice you can use iteration until you reach the desired accuracy or other sorts of approximation. Since this can be done to machine precision, it is a solved problem in numerical analysis.

martinvicanek  Posts: 846
 Joined: Sat Jun 22, 2013 8:28 pm
Re: DSP code module and power (or root) function
martinvicanek wrote:tulamide wrote: So, I really wonder, do any of you know of a way to realize inverse power with just simple arithmetics?
There is no closed form in terms of a finite number of elementary operations (+,,*,/) except for integer powers. In practice you can use iteration until you reach the desired accuracy or other sorts of approximation. Since this can be done to machine precision, it is a solved problem in numerical analysis.
I confess, I hoped for a dsp code example. Did nobody ever need to use inverse power?
 tulamide
 Posts: 1811
 Joined: Sat Jun 21, 2014 2:48 pm
 Location: Germany
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 10 guests