[futurebasic] Re: [FB] Signed and unsigned comparison

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2007 : Group Archive : Group : All Groups

From: Jay Reeve <jayreeve@...>
Date: Sat, 12 May 2007 19:00:28 -0500
On May 12, 2007, at 5:14 AM, Robert Purves wrote:

>
> Comparisons (>, >=, <, <=) of pointer variables in FB are always  
> signed. Needing an unsigned '>' comparison, I found it necessary to  
> use the clumsy function UnsignedGreaterThan() below, with its  
> unpleasant lapse into assembler.
> Can someone supply a more elegant method?
>
> Robert P.


Still a bit kludgy perhaps, but this seems to work...

   e-e
   =J= a  y
    "

_sgnBit = bit( 31 )
// unsigned comparison: _zTrue if p1 > p2
local fn UnsignedGreaterThan( p1 as ptr, p2 as ptr )
'~'1
dim as boolean p1Greater
long if ( p1 and _sgnBit ) == ( p2 and _sgnBit )
p1Greater = ( p1 nand _sgnBit ) > ( p2 nand _sgnBit )
xelse
p1Greater = ( p2 and _sgnBit ) == 0
end if
end fn = p1Greater