Re: Negative margins

Sho Kuwamoto wrote:
> So, combining (1.2) and (2.2), the algorithm to compute the
> space between block-level elements would be:
> 
> if (a >= 0 && b>= 0)
> 	space = max(a,b);
> 
> else if ( (a >= 0 && b < 0) || (a < 0 && b >= 0) )
> 	space = a+b;
> 
> else // a < 0 && b < 0
> 	space = -max(-a,-b);
> 
> Any thoughts?

Well, if you're doing it in 32-bit x86 assembler, I think this will do
the job quite quickly:

   mov   eax,margin1
   mov   ebx,margin2
   cmp   eax,ebx
   jg    greaterax
   xchg  eax,ebx
   jbe   switcheck
addem:
   add   eax,ebx
   jmp   done
greaterax:
   jb    addem
switcheck:
   or    eax,eax
   jns   done
   xchg  eax,ebx
done:
                  ; eax now has margin

David Perrell

Received on Monday, 21 July 1997 22:28:36 UTC