rounding stream and the magic NR!?
Posted: Wed May 15, 2013 7:03 pm
hi, as already worked out with troga little bit in my ppq stepposition thread, there are some questions about rounding in stream, spezially to round down to int, here i have 3 methods of how to do it and their behaviors,
the first one in both examples always works right but is cpu intensive, the most common method to subtract 0.5 works with 0.4999995! this is the real magic number trog told me while ago that it is 0.49999997!? so can there be a difference in different cpus? or did something changed in FS and why does 0.4999996 works with the number 8 but not with 9?
the second often used method is:
rounded = rndint(x)
rounded = rounded -1(rounded > x)
here you have to do a variable that it works right, like:
rnd = rndint(x)
rounded = rnd - 1 (rnd > x)
the first one in both examples always works right but is cpu intensive, the most common method to subtract 0.5 works with 0.4999995! this is the real magic number trog told me while ago that it is 0.49999997!? so can there be a difference in different cpus? or did something changed in FS and why does 0.4999996 works with the number 8 but not with 9?
the second often used method is:
rounded = rndint(x)
rounded = rounded -1(rounded > x)
here you have to do a variable that it works right, like:
rnd = rndint(x)
rounded = rnd - 1 (rnd > x)