Hi!

That was a good question, I think sorting where to use "modular synth style" signal flow and where to us "plain code" is a important part of ChucKing. Many things can be done both ways but if you do it the "wrong" way you'll end up with ugly code and high cpu costs.

If there is still a need to round to a multiple of some number in a "5.trunc(2);" style it could be done using something like this;

fun float trunc(float input, float multiple)
  {
  return (input - input%multiple);
  }


which will always round down. If we really need the closest value we can use something like;


fun float trunc(float input, float multiple)
  {
  if ( input%multiple < ( .5 * multiple)  ) return (input - input%multiple);
  else return (input - input%multiple + multiple);
  }


This would be overkill if we just want a series of tones that hits every multiple of 400Hz (in that case we'd be much better off with simply generating that series directly like Ge said) but it's still a valid question in itself.

Hope that helps.
Kas.