[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] frac semantic



The lang version of .frac is equivalent to n%1. In terms of usefulness, then, it might be better to go with the ugen definition of .frac, so both possibilities are covered.


The lang version currently is the same as the ugen version:



-1.2.frac // -0.2
1.2.frac // 0.2
{ DC.ar(-1.2).frac.poll }.play; // -0.2
{ DC.ar(1.2).frac.poll }.play; // 0.2

-1.2 % 1 // 0.8
1.2 % 1 // 0.2

{ (DC.ar(-1.2) % 1).poll }.play; // 0.8
{ (DC.ar(1.2) % 1).poll }.play; // 0.2

At 11:24 Uhr +0100 21.12.2009, Tim Blechmann wrote:
> The lang version of .frac is equivalent to n%1. In terms of usefulness, then, it might be better to go with the ugen definition of .frac, so both possibilities are covered.

yes, i would also prefer this behavior ... if no one objects, i will
commit a patch, changing the sclang semantic of frac to match the unit
generator ...

so what of the above behavior is changed by your patch?





- Scott

On Dec 17, 2009, at 10:33 AM, Tim Blechmann wrote:

 according to the supercollider docs, the frac operator is defined as:
 frac .. fractional part [1]

 the unit generator implements it as defined in wikipedia (according to
 Graham, Knuth, & Patashnik) [2]:
 x - floor(x)

 the language as defined at wolfram [3] and the c99 modf function [4]:
 x - trunc(x)

 for positive x, the result is the same, for negative x, the first
 formula returns positive values, the second version negative values.


 the only version, where this is actually used in the class library is
 the implementation of LinLin. for this use case, the implementation
 doesn't matter though:
 ^LinLin.ar(in.frac, 0.0, 1.0, val0, val1);
 ^LinLin.kr(in.frac, 0.0, 1.0, val0, val1);


 although i don't like breaking backwards compatibility, i think, it is
 useful here in order a consistent behavior in language and server.
 especially since the specification is not precise. it shouldn't touch
 too much code and if people made use of it, i hope, they were aware of
 the imprecise specification. personally i am not sure about the best
 definition, though ... while i like using the definitions, used by
 mathematicians, i also like the consistency with modf.

 so, i'd be curious to hear thoughts about this ...

 tim


 [1] build/Help/Language/Operators.html
 [2] http://en.wikipedia.org/wiki/Floor_and_ceiling_functions#Fractional_part
 [3] http://mathworld.wolfram.com/FractionalPart.html
 [4] http://opengroup.org/onlinepubs/007908799/xsh/modf.html


 --
 tim@xxxxxxxxxx
 http://tim.klingt.org

 It is better to make a piece of music than to perform one, better to
 perform one than to listen to one, better to listen to one than to
 misuse it as a means of distraction, entertainment, or acquisition of
 'culture'.
 John Cage




_______________________________________________
sc-dev mailing list

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


--





.

_______________________________________________
sc-dev mailing list

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