What does rsqrt~ do ?

Cheng Chien-Wen's icon

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.

Awksijek's icon

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

José Manuel Berenguer's icon
srs's icon

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?

MIB's icon
srs's icon

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?

AlexHarker's icon

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.

Roman Thilenius's icon

to implement rsqrt in maxmsp, you can use expression:

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

only one object and more accurate.

-110

srs's icon

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

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

Roman Thilenius's icon

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:

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)]

srs's icon

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?

Roman Thilenius's icon

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.^^