On Thu, 5 Mar 2009, Jeremy White wrote: [...]
+ /* Note that conversion of float -> SANE_Fixed is lossy; + * and when you truncate it into an integer, you can get + * unfortunate results. This calculation attempts + * to mitigate that harm */ if (s_quant) - pos = (dd / s_quant); + pos = ((dd + (s_quant/2.0)) / s_quant); else - pos = dd / 0.01; + pos = (dd + 0.005) / 0.01;
pos is an integer. So why not simply round to the nearest instead of rounding down (which is the default for double -> int conversions)? if (s_quant) pos = lround(dd / s_quant); else pos = lround(dd / 0.01); -- Francois Gouget <fgouget(a)free.fr> http://fgouget.free.fr/ Hiroshima '45 - Czernobyl '86 - Windows '95