multiplying signals

View: New views
8 Messages — Rating Filter:   Alert me  

multiplying signals

by 344server :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello List,

Why is s*s different from s**2?



{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s*s);
}.scope;

{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s**2);
}.scope;





.
.
.
.
.
+351 96 566 57 48
.
chat: mmcvirus
skype: mcardoso_soopa.org


Re: multiplying signals

by Michael G. Cox :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

{SinOsc.ar.squared}.plot
gives the same result as s*s
which is the correct result.

s**2 seems to be incorrect.
No idea why, though.

-mgc

On Sat, Apr 18, 2009 at 12:09 PM, Miguel Cardoso <mcardoso@...> wrote:
Hello List,

Why is s*s different from s**2?



{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s*s);
}.scope;

{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s**2);
}.scope;





.
.
.
.
.
+351 96 566 57 48
.
chat: mmcvirus



Re: multiplying signals

by Scott Wilson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For UGens pow is defined to maintain sign:

inline float sc_pow(float a, float b)
{
return a >= 0.f ? std::pow(a, b) : -std::pow(-a, b);
}

S.

On 18 Apr 2009, at 20:28, michael cox wrote:

{SinOsc.ar.squared}.plot
gives the same result as s*s
which is the correct result.

s**2 seems to be incorrect.
No idea why, though.

-mgc

On Sat, Apr 18, 2009 at 12:09 PM, Miguel Cardoso <mcardoso@...> wrote:
Hello List,

Why is s*s different from s**2?



{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s*s);
}.scope;

{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s**2);
}.scope;





.
.
.
.
.
+351 96 566 57 48
.
chat: mmcvirus




Re: multiplying signals

by andrea valle-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why?

Thanks

Best

-a-

On 18 Apr 2009, at 21:30, Scott Wilson wrote:

For UGens pow is defined to maintain sign:

inline float sc_pow(float a, float b)
{
return a >= 0.f ? std::pow(a, b) : -std::pow(-a, b);
}

S.

On 18 Apr 2009, at 20:28, michael cox wrote:

{SinOsc.ar.squared}.plot
gives the same result as s*s
which is the correct result.

s**2 seems to be incorrect.
No idea why, though.

-mgc

On Sat, Apr 18, 2009 at 12:09 PM, Miguel Cardoso <mcardoso@...> wrote:
Hello List,

Why is s*s different from s**2?



{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s*s);
}.scope;

{
var f=200, s;
f.postln;
s = SinOsc.ar(f);
Out.ar([0,1], s**2);
}.scope;





.
.
.
.
.
+351 96 566 57 48
.
chat: mmcvirus




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - DAMS
Università degli Studi di Torino
--------------------------------------------------
" This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)


Re: multiplying signals

by James Harkins-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Helpfile for '**':

"When the signal is negative this function extends the usual definition of exponentiation and returns neg(neg(a) ** b). This allows exponentiation of negative signal values by noninteger exponents."

That is, SinOsc.ar.sqrt would produce nan very quickly without this tweak.

But this is only for the BinaryOpUGen implementation. Integers and Floats in the language behave as you'd expect.

-2**0.5 --> nan

hjh


On Apr 18, 2009, at 3:46 PM, Andrea Valle wrote:

Why?


: H. James Harkins
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman


Re: multiplying signals

by Wouter Snoei-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi James,

shouldn't this difference in behaviour for UGens and Integers/Floats  
should be mentioned in the ** helpfile? Maybe with an extra example  
which shows the difference? I can imagine people getting confused  
about this when using it both in the lang and for UGens. Something  
like this:

{ Line.ar(-1,1,0.01).abs ** 2 }.plot;

({ |i| i.linlin(0, 99, -1, 1) ** 2 } ! 100).plot;

And, is there also an exponentiation BinaryOpUGen that does the  
mathematically correct version?

cheers,
Wouter

Op 18 apr 2009, om 22:13 heeft James Harkins het volgende geschreven:

> Helpfile for '**':
>
> "When the signal is negative this function extends the usual  
> definition of exponentiation and returns neg(neg(a) ** b). This  
> allows exponentiation of negative signal values by noninteger  
> exponents."
>
> That is, SinOsc.ar.sqrt would produce nan very quickly without this  
> tweak.
>
> But this is only for the BinaryOpUGen implementation. Integers and  
> Floats in the language behave as you'd expect.
>
> -2**0.5 --> nan
>
> hjh
>
>
> On Apr 18, 2009, at 3:46 PM, Andrea Valle wrote:
>
>> Why?
>
>
> : H. James Harkins
> : jamshark70@...
> : http://www.dewdrop-world.net
> .::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:
>
> "Come said the Muse,
> Sing me a song no poet has yet chanted,
> Sing me the universal."  -- Whitman
>


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: multiplying signals

by Wouter Snoei-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oops should have removed the .abs (although it plots the same)

{ Line.ar(-1,1,0.01) ** 2 }.plot;

({ |i| i.linlin(0, 99, -1, 1) ** 2 } ! 100).plot;

Op 19 apr 2009, om 17:30 heeft Wouter Snoei het volgende geschreven:

> Hi James,
>
> shouldn't this difference in behaviour for UGens and Integers/Floats  
> should be mentioned in the ** helpfile? Maybe with an extra example  
> which shows the difference? I can imagine people getting confused  
> about this when using it both in the lang and for UGens. Something  
> like this:
>
> { Line.ar(-1,1,0.01).abs ** 2 }.plot;
>
> ({ |i| i.linlin(0, 99, -1, 1) ** 2 } ! 100).plot;
>
> And, is there also an exponentiation BinaryOpUGen that does the  
> mathematically correct version?
>
> cheers,
> Wouter
>
> Op 18 apr 2009, om 22:13 heeft James Harkins het volgende geschreven:
>
>> Helpfile for '**':
>>
>> "When the signal is negative this function extends the usual  
>> definition of exponentiation and returns neg(neg(a) ** b). This  
>> allows exponentiation of negative signal values by noninteger  
>> exponents."
>>
>> That is, SinOsc.ar.sqrt would produce nan very quickly without this  
>> tweak.
>>
>> But this is only for the BinaryOpUGen implementation. Integers and  
>> Floats in the language behave as you'd expect.
>>
>> -2**0.5 --> nan
>>
>> hjh
>>
>>
>> On Apr 18, 2009, at 3:46 PM, Andrea Valle wrote:
>>
>>> Why?
>>
>>
>> : H. James Harkins
>> : jamshark70@...
>> : http://www.dewdrop-world.net
>> .::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:
>>
>> "Come said the Muse,
>> Sing me a song no poet has yet chanted,
>> Sing me the universal."  -- Whitman
>>
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: multiplying signals

by James Harkins-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Apr 19, 2009, at 11:30 AM, Wouter Snoei wrote:

shouldn't this difference in behaviour for UGens and Integers/Floats should be mentioned in the ** helpfile?

I suppose so, but I didn't write that help file. Maybe I can get to it before 3.3.

And, is there also an exponentiation BinaryOpUGen that does the mathematically correct version?

Not to my knowledge. It's riskier for signals anyway, because exponentiation of negative numbers is valid (as far as I can see) for integers only.

It's been this way since sc2 and there hasn't been a great uproar over it in several years, so I wouldn't anticipate this changing anytime soon.

hjh


: H. James Harkins
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman