[sane.ds 2/4] Fix a subtle bug that prevented the float scrollbar from incrementing by one.

Francois Gouget fgouget at free.fr
Fri Mar 6 05:36:40 CST 2009


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 at free.fr>              http://fgouget.free.fr/
                  Hiroshima '45 - Czernobyl '86 - Windows '95



More information about the wine-devel mailing list