roundToIntAccurate vs roundDoubleToInt


I’m having problems with a VST in different hosts, and the fail is in the roundToIntAccurate() function, which I thought that was an exact way to round possitive values, but it seems that 0.5 drives crazy both functions, and they offer different results if the integer part is odd or even.

From roundDoubleToInt doc:

From roundToIntAccurate

Does it mean that roundToIntAccurate can round up or round down randomly values with floating point 0.5 like roundDoubleToInt does? If it does that, which is the drawback from using roundDoubleToInt vs using roundToIntAccurate?

Edit: The most hosts work fine, as expected, rounding 0.5 towards up, except some like FL Studio 10, that round odd and even numbers as it wants. It seems that roundToIntAccurate doesn’t have effect in FL Studio, and it works like roundDoubleToInt


Sounds like some hosts (or other plugins within them) are messing with the CPU’s floating point flags. If that happens, then all bets are off as to exactly how your floating point operations will behave. You could reset the CPU flags yourself before calling whatever function this all lives in, but of course that might mess up the host if it’s expecting some other mode. Maybe the question you should be asking is why your code can be broken by subtle changes in hardware-specific floating point behaviour, and whether you could write it in a more robust way?


Yes, i found a way to do it robust and inmune to those problems, they were pretty visible: I was snapping few lines to pixel’s screen and it was really awful because the lines were dancing while you resize the window.

I think that roundToIntAccurate follow something like to this criteria:


without necessarily endorsing the juce round to int functions, i’d like to add:

the default rounding mode of IEEE754-2008 is “round to nearest even”. when a number falls halfway between two consecutive floating point numbers, a tie breaking rule is chosen; round to even rounds to the one of these whose integral significand is even.