What does rsqrt~ do ?

Aug 27, 2006 at 6:21am

What does rsqrt~ do ?

I saw some patch graphs in the paper which use rsqrt~. I tried to find this object in Max/MSP object data base but in vain.

Does any one know what function it might serve ?

(sqrt~: squre root)

Thanks.

#27316
Aug 27, 2006 at 6:54am

rsqrt~ is a native PD object. Not Max/MSP. I can’t tell you what it does, though.

#82535
Aug 27, 2006 at 9:26am

#82536
Oct 29, 2010 at 1:32am

has anyone found an answer to this? i also came across a rsqrt~ object in an example in an fft paper on cross convolution and from the puredata docs, its seems like its a reciprocal square root (1/sqrt(x)) function..

i’ve been implementing it in max as such but don’t know if its as simple as that

thoughts anyone?

#82537
Oct 29, 2010 at 2:37am

google’s your friend :)

https://wiki.puredata.info/en/rsqrt~

#82538
Oct 29, 2010 at 2:12pm

sorry – i wasn’t clear enough in my post. i’ve been implementing it as 1/sqrt(x) where sqrt(x) is just the Max library object but in the puredata docs the object performs the function “using a fast, approximate algorithm which is probably accurate to about 120 dB (20 bits).”

similar methods are described elsewhere and this sounds like a more complex approach than just dividing 1 by the output of the in-built sqrt object’s output… or is it.

anyone elses thoughts?

#82539
Oct 29, 2010 at 3:53pm

rsqrt~ is simply calculating 1/sqrt(x), but only to a certain accuracy. This makes it faster / less expensive.

This is a math call common in programming libraries that saves processing power in tasks where the increased accuracy is not needed. Implementing 1 / sqrt(x) is fine as a replacement, and there is *probably* no need to worry on a modern processor about the speed.

#82540
Oct 29, 2010 at 5:00pm

to implement rsqrt in maxmsp, you can use expression:

[expr~ 1./srqt($f12)]

only one object and more accurate.

-110

#82541
Oct 30, 2010 at 3:10pm

Thanks for your replies – Roman, can I ask how you reached the equation in that expression?

Looking at the the source code for rsqrt~ in pd (in d_math.c) it looks as though its based on this algorithm

http://en.wikipedia.org/wiki/Fast_inverse_square_root#Overview_of_the_code

which makes sense given it’s description in the pd docs but looks like it would need a c external to implement in max.

#82542
Oct 30, 2010 at 5:07pm

i guessed it, it might be wrong.

well there is a lot of code on the wikipedia site. :)

one of them is what i suggested:

http://upload.wikimedia.org/math/b/b/5/bb56561eddeafb2a43230a9a91d10d5e.png

edit:

i have no idea how to read that c code.
but implemeting an “only if input is greater than 1 for the sqrt argument seems a good idea.

in expr we could let it output 0 as result when the user is so stupid and asks for the 0.7th square root:

[expr~ (1./srqt($f1$f2))*($f2>1)]

#82543
Nov 1, 2010 at 12:45am

ok – thanks. i guess the fact that no one seems to have already made a c external that implements the algorithm in pd’s rsqrt~ object means that it might not be necessary and that just a simple 1/sqrt(x) is accurate enough.

i’m using it for some of the fft bin operations in settel and lippe’s papers – anyone else doing something similar?

#82544
Nov 1, 2010 at 1:58am

it is _more accurate to use 1/sqrt(x) – 53 bits inside [expr] – which is why it takes up far
more CPU than the clever method found in rsqrt.

and actually it seems like a joke that rsqrt is available to pd users but not with jitter,
where a recip. sqrt is probably more used than in audio or logic programming.

edit (bad manner, i know):

i have no idea, is the audio expr~ coming with maxmsp now? and is it available for
windows?
you might better stay with the math objects and ignore my above expr.^^

#82545

You must be logged in to reply to this topic.