Okay, i just figured out that Math.trunc(x) just truncates x to the nearest integer - it'd be nice to have something to round to arbitrary values, though.  Is there, for instance, a nicer way to round the output of a low-frequency saw wave than this?  This just seems laborious:

----

SinOsc sin => dac;
SawOsc saw;

   1 => saw1.freq;
   0 => saw1.phase;

 

saw1 => blackhole;

while (true)
{
400.00 * (Math.trunc(((saw1.last() * 2000.0) + 2000.0) / 400.0)) => sin.freq;
// saw1 goes from 0 to 4000 at a speed of 1 Hz
// and is rounded to the nearest 400
1::samp => now;
};


---
thanks,

jascha




On Oct 7, 2007, at 10:44 PM, Jascha Narveson wrote:



This should be an easy function to use, but i can't for the life of  
me figure the syntax out - i've tried

5 => Math.trunc(2);

and

Math.trunc(5,2);

and

5.trunc(2);  // this would be the nicest syntax

and some other things, to no avail - the documentation isn't big on  
examples for stuff like this.



thanks,

jascha
_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users