Hi list,
It looks like the mrpeach [packOSC] external converts Pd floats to OSC integers if the float value is equal to the float value cast to an int. From the source code:
/* It might be an int, a float, or a string */ switch (a->a_type) { case A_FLOAT: f = atom_getfloat(a); i = atom_getint(a); if (f == (t_float)i) { /* assume that if the int and float are the same, it's an int */ returnVal.type = INT_osc;
Implicitly converting floats to integers based on an arbitrary rule seems a bad idea to me. Why bother making the conversion? Why not send floats as floats?
It's certainly going to cause problems for some clients. For example, if the client is expecting floats on a given OSC address, it may get:
0.5 -> float 1.0 -> int ??? 1.5 -> float
Which may result in dropped values or other anomalies.
I am happy to send a code patch if people agree that this is a bug or at least bad design...
best,
Jamie
I guess it's because all numbers in Pd are floats, but usually integer floats are meant to be integers. But obviously it's impossible for the code to know what the user wants, so you can also force the type by using the [sendtyped ...( message. Probably sending all numbers as floats will annoy an approximately equal number of people.
Martin
On 2012-09-07 07:11, Jamie Bullock wrote:
Hi list,
It looks like the mrpeach [packOSC] external converts Pd floats to OSC integers if the float value is equal to the float value cast to an int. From the source code:
/* It might be an int, a float, or a string */ switch (a->a_type) { case A_FLOAT: f = atom_getfloat(a); i = atom_getint(a); if (f == (t_float)i) { /* assume that if the int and float are the same, it's an int */ returnVal.type = INT_osc;
Implicitly converting floats to integers based on an arbitrary rule seems a bad idea to me. Why bother making the conversion? Why not send floats as floats?
It's certainly going to cause problems for some clients. For example, if the client is expecting floats on a given OSC address, it may get:
0.5 -> float 1.0 -> int ??? 1.5 -> float
Which may result in dropped values or other anomalies.
I am happy to send a code patch if people agree that this is a bug or at least bad design...
best,
Jamie _______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Hi Martin,
On 7 Sep 2012, at 14:13, Martin Peach martin.peach@sympatico.ca wrote:
I guess it's because all numbers in Pd are floats, but usually integer floats are meant to be integers. But obviously it's impossible for the code to know what the user wants, so you can also force the type by using the [sendtyped ...( message. Probably sending all numbers as floats will annoy an approximately equal number of people.
Hmm... surely if it's impossible to know what the user wants, the best thing to do is just pass the values along without converting them. The client then has the option to coerce whole-number floats to ints if it wants to.
Anyhow, if I can force all numbers to be floats with [sendtyped ...( that solves my my problem in practical terms.
best,
Jamie