roundToInt() rounding .5 down

Hi, roundToInt() is rounding .5 values down whereas I would expect them to be going up. I’m pretty sure this used to be correct.

thx

Confirmed:

roundToInt(0.5f) == 0
(int)round(0.5f) == 1

/** Fast floating-point-to-integer conversion.

    This is faster than using the normal c++ cast to convert a float to an int, and
    it will round the value to the nearest integer, rather than rounding it down
    like the normal cast does.

    Note that this routine gets its speed at the expense of some accuracy, and when
    rounding values whose floating point component is exactly 0.5, odd numbers and
    even numbers will be rounded up or down differently.
*/

ok, thx for the clarity - the only reason I raised is that a recent pull seems to have changed the behaviour.

I don’t remember seeing any changes to it for a long time, but it’s always been a “fast-and-dirty” converter, not a function that you should use if you care about exact values.

understood, thx

I just checked the git log for this file, it was a change from 9 January this year (develop, I did not check master)

I see rather 3 years for that function, doing git blame:

Sorry, my mistake, I interpreted the diff incorrectly :frowning: