From ec534af68815e6bd1ddf6eebea053a762e264deb Mon Sep 17 00:00:00 2001 From: Emlyn Corrin Date: Thu, 22 Feb 2024 00:43:01 +0000 Subject: [PATCH] Allow range to return ints if all args are ints --- app/server/ruby/lib/sonicpi/lang/core.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/server/ruby/lib/sonicpi/lang/core.rb b/app/server/ruby/lib/sonicpi/lang/core.rb index 7729c93afc..70c94114e0 100644 --- a/app/server/ruby/lib/sonicpi/lang/core.rb +++ b/app/server/ruby/lib/sonicpi/lang/core.rb @@ -1772,8 +1772,6 @@ def spread(num_accents, size, *args) def range(start, finish, *args) - start = start.to_f - finish = finish.to_f if is_list_like?(args) && args.size == 1 && args.first.is_a?(Numeric) # Allow one optional arg for legacy reasons. Versions earlier # than v2.5 allowed: range(1, 10, 2) @@ -1781,11 +1779,17 @@ def range(start, finish, *args) inclusive = false else args_h = resolve_synth_opts_hash_or_array(args) - step_size = args_h[:step] || 1.0 - step_size = step_size.to_f + step_size = args_h[:step] || 1 inclusive = args_h[:inclusive] end + # If all args are ints, return ints + unless start.is_a? Integer and finish.is_a? Integer and step_size.is_a? Integer then + start = start.to_f + finish = finish.to_f + step_size = step_size.to_f + end + return [].ring if start == finish raise ArgumentError, "step size: opt for fn range should be a non-zero number" unless step_size != 0