Re: [dev] dwm-5.6

From: Preben Randhol <randhol_AT_pvv.org>
Date: Fri, 17 Jul 2009 18:58:27 +0200

On Fri, 17 Jul 2009 13:51:35 +0200
Szabolcs Nagy <nszabolcs_AT_gmail.com> wrote:

> On 7/17/09, Szabolcs Nagy <nszabolcs_AT_gmail.com> wrote:
> > it turns out the result of those inequalities depend on compiler
> > optimization flags (compiler might choose to use double division and
> > comparison instead of float one) so with -O0 there are no updates,
> > with -Os there are always updates unless the aspect is a "nice"
> > ratio.
>
> hm it's worse than that, even -O0 uses double comparison there, a
> float cast is not enough.
>
> one can get expected behaviour with using -O0 flag and something like
>
> if(c->mina > 0 && c->maxa > 0) {
> + float a1 = (float)*w / *h;
> + float a2 = (float)*h / *w;
> +
> - if(c->maxa < (float)*w / *h)
> + if(c->maxa < a1)
> *w = *h * c->maxa;
> - else if(c->mina < (float)*h / *w)
> + else if(c->mina < a2)
> *h = *w * c->mina;
> }
>
> and then indeed no unnecessary updates occur
>
> moral of the story: don't rely on (float)a/b == (float)a/b

But of course!

(float)*w/(float)*h != (float) (w/h) in most cases also...

assuming w and h are ints.

-- 
Preben Randhol
Received on Fri Jul 17 2009 - 16:58:27 UTC

This archive was generated by hypermail 2.2.0 : Fri Jul 17 2009 - 17:00:01 UTC