[chuck-users] Math.trunc

Jascha Narveson jnarveson at wesleyan.edu
Sun Oct 7 23:13:23 EDT 2007


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 at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20071007/e6d24e2d/attachment.htm 


More information about the chuck-users mailing list