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

[sc-dev] Rounding 'n' for do, Array.fill etc.?

Since when does Array.fill round the number of items to the nearest
integer (instead of truncating)?

Array.fill(1.6, { |i| i });
--> [ 0, 1 ]

Two elements? That seems incorrect to me.

For that matter, 'do':

1.4.do { |i| i.postln }; ""  // prints 0
1.6.do { |i| i.postln }; ""  // prints 0 and 1

Did I just never notice that this is what it's doing? Or has it really
always been that way?

I can't say I especially like this behavior. IMO, a number of
iterations is inherently an integer. If you give it a float, it should
be implicitly cast to integer, and that usually implies truncation of
the fractional part, not rounding. But, if it's always been like this
and people are relying on it, then I can live with writing the
explicit type-cast in my code.


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/