Floats mysteriously cast to integers in list input using js in Max
Hi everybody! This is my first post here so please bear with me if I'm not yet super familiar with posting conventions on this forum.
I'm trying to make a Max abstraction using JavaScript to generate sequences of evenly spaced numbers from A to B in N steps (see the seq() function in R for an example) and running into a really silly problem where floating point numbers I send through my JS code in a list are interpreted as integers.
I've narrowed the problem down to this code excerpt:
inlets=2;
// if the program receives a list and it is from the left inlet,
// use its first two terms to update A and B
function list(v) {
//assign inlets with if statements
if (inlet==0) A = arguments[0]
if (inlet==0) B = arguments[1]
by = (B-A)/(N-1)
seq() // update generated sequence
}
If I try to get a sequence from 0 to 10 in 20 steps, my code works, but if I ask for a sequence from 0 to 2.5 in 5 steps, my program returns a sequence from 0 to 2 in 5 steps, essentially interpreting my floats as the nearest floored (I think) integer.
Does anybody have any idea what's going on?
Any help would be super appreciated! I'm also interested in alternative approaches to this list generation tool! Let me know your thoughts!
Here is a diluted version of the patcher I'm working on:
Here is an even simpler reproducible example:
If I use a pack object to pack two float values into a list and send it through the first outlet of the js object, it collects the values and posts them to the Max console, however, somewhere along this process they are cast to integers.
var A = 0.0;
var B = 0.0;
function list(v) {
//assign inlets with if statements
if (inlet==0) A = arguments[0]
if (inlet==0) B = arguments[1]
post(A, B)
}
Hi, you need to set the type of elements of a [pack].
[pack f f] for 2 floats.
Thank you so much! I knew I was missing something obvious! Works like a charm now!