On Fri, May 17, 2002 at 03:27:44PM -0400, Dan Sugalski wrote:
> At 8:04 PM +0100 5/17/02, Nicholas Clark wrote:
> >On Thu, May 16, 2002 at 08:37:32PM -0400, Dan Sugalski wrote:
> >> Pssst. Brent. Don't tell anyone, but ~0 *is* -1... :)
> >
> >$ perl -le 'print ~0'
> >4294967295
> >$ perl -le 'print -1'
> >-1
> >
> >What language were we talking about? :-)
> 
> C, of course. Perl's floating point and integer semantics are another 

Do any platforms exist where integers are stored either in 1s complement, or
as sign and magnitude? [Your C is a subset of ANSI C :-)
Admittedly the useful subset]

> matter entirely. Pity that Doing The Right Thing is such a pain. :(

Well, it was more doing the right thing with backwards compatibility.
*If* perl programmers wrote ~0 when they meant (unsigned int)-1
[or perl6 forced this discipline onto them] then it would be possible to
have -4.99, -5.0 and -5.01 convert to 0 in unsigned context, which some
people see as more reasonable.
The upshot of keeping things locally sane is that -Inf converts to 0x80000000
in unsigned context. (on a system with 32 bit integers)

(Yes, perl5 does assume a 2s complement in the C code, but I have a patch
locally that I believe eliminates all places where that assumption is made)

The trouble is, that everyone is used to DWIM, and $foo & -1 meaning
$foo & ~0, so it would probably not be a good thing to change.

Nicholas Clark
-- 
Even better than the real thing:        http://nms-cgi.sourceforge.net/

Reply via email to