1 Hz error

jaiserpe's icon

[kslider]—[mtof]—[numberBox]

 

How come, if I press the A key (corresponding to 880 Hz), the [numberBox] shows 879.

 

It is only 1 Hz error, but it shouldn’t be.

jaiserpe's icon

with [float] it is ok, 880.

but with [integer] it is not ok.

TFL's icon

This is a rounding error, probably inserted in the [mtof] calculation. The exact value being output is 879.999999507248162, which gets truncated to 879 when interpreted as an integer, but shown as 880 when sent to a float number box which will round the displayed result depending on the objects size and numdecimalplaces attribute.

Max Patch
Copy patch and select New From Clipboard in Max.

You'll probably want to use floats here anyway (in order to preserve precision in the low end), but if you really really want integers, best it to [round] the float value.

Roman Thilenius's icon

besides more complicated explanations for the given case, let me put it like this: you generally should round float to int, in almost all situations.