Martin Peach wrote:
Yes but why? You can accurately represent every 32-bit int with a float, but Pd clips them by using the %g format specifier to print them, instead of %f.
Ooops not true, only up to 24 bits are exact, after that integers increment by increasing powers of two; but using %g to format floats loses precision before that compared to %f.
In m_atom.c, at line 68, the function atom_string() converts atoms into strings, and in the case of float atoms, uses this line to do it:
sprintf(tbuf, "%g", a->a_w.w_float);
This prints both of the floats 16777215.0 and 16777214.0 as "167772e+7". It seems to me that
sprintf(tbuf, "%f", a->a_w.w_float);
would be better, since it prints 16777215.000000, 16777214.000000.
Or even better a routine to clip off unnecessary trailing zeros and decimal points: int i; i = sprintf(tbuf, "%f", a->a_w.w_float); while ((--i > 0) && (tbuf[i] == '0')) tbuf[i] = '\0'; if tbuf[i] = '.' tbuf[i] = '\0';
I'll post this as a patch for atom_string() later today.
Martin