There’s a tricky detail that prevents that snippet from producing your desired graph (aside from the precendence bit). Compare the following:
(
{
var t = Line.ar(-1.5, 1.5, 0.01);
var pow1, pow2, pow3, pow4;
pow1 = t.pow(2);
pow2 = t ** 2;
pow3 = t.squared;
pow4 = t * t;
[pow1, pow2, pow3, pow4]
}.plot;
)
As you can see, .pow
and **
don’t work the way you might think they do inside UGen graph functions. pow(a, b)
is actually defined as sign(a) * pow(abs(a), b)
when it is used as a BinaryOpUGen
, as documented here. There’s also a forum thread that goes into detail on why that implementation actually makes sense. Compare this to the same operation done on the language side:
(
var t;
var pow1, pow2, pow3, pow4;
t = (0..1024).linlin(0, 1024, -1.5, 1.5);
pow1 = t.pow(2);
pow2 = t ** 2;
pow3 = t.squared;
pow4 = t * t;
[pow1, pow2, pow3, pow4].plot; // all give same result
)
Here’s a corrected version that produces the desired result:
(
{
var t = Line.ar(-1.5, 1.5, 0.01);
((10 * cos(2pi * (5 * t))) + (5 * cos(2pi * (40 * t)))) * exp(-pi*(t.squared))
}.plot;
)