[31690] in Perl-Users-Digest
Perl-Users Digest, Issue: 2953 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 19 21:09:43 2010
Date: Wed, 19 May 2010 18:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 19 May 2010 Volume: 11 Number: 2953
Today's topics:
Re: bit-twiddling on 32-bit machines <ben@morrow.me.uk>
Re: bit-twiddling on 32-bit machines sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 May 2010 23:44:50 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: bit-twiddling on 32-bit machines
Message-Id: <286ec7-6f8.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2010-05-19, Ben Morrow <ben@morrow.me.uk> wrote:
> >
> > Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> >> On 2010-05-18, Ben Morrow <ben@morrow.me.uk> wrote:
> >> >
> >> > Depending on what you're doing, promotion to double *should* safely give
> >> > you 53 bits of integer precision, but you may want to consider
> >> > rebuilding your perl with -Duse64bitint to avoid type conversion all
> >> > over the place. The standard FreeBSD build has been built with this
> >> > option for a while now, and there is some talk of using it for the
> >> > Debian builds of 5.12.
> >>
> >> Having int wider than float type is a VERY large can of worms (well,
> >> at least it was the last time I was looking; did things change
> >> recently?).
> >
> > That's all been fixed, I think by Nick Clark during 5.8. A whole lot of
> > code in {pp,sv}.c is now conditional on NV_PRESERVES_UV, which is
> > determined by Configure.
>
> Looks like I might have been not very specific. The can of worms I
> meant is with the semantic, not implementation - things "not behaving
> as expected" vs things behaving "obviously wrong".
Can you give an example of things not behaving as expected? AFAICS using
long integers makes numeric semantics *more* predictable, by avoiding
conversion to floats for longer.
In any case, this has been an issue ever since perl started building on
64bit platforms with only a 53bit double type.
> This thread is one example of the "first category" - if one forgets
> what happens with `use integer', which is obviously a bug (BTW, is it
> reported yet?).
Not by me. With a perl with 32bit IVs I get
~% perl -E'
my $x = (1<<30); say $x;
$x <<= 1; say $x;
$x <<= 1; say $x;'
1073741824
-2147483648
0
I presume it's the final '0' you consider a bug, not the negative value?
I'm not sure I agree that's a bug, since perldoc integer says
| Finally, "use integer;" also has an additional affect on the bitwise
| operators. Normally, the operands and results are treated as
| unsigned integers, but with "use integer;" the operands and results
| are signed. This means, among other things, that ~0 is -1, and -2 &
| -5 is 6.
|
| Internally, native integer arithmetic (as provided by your C
| compiler) is used. This means that Perl’s own semantics for
| arithmetic operations may not be preserved.
and a C program the does the same operations on a signed 32bit integer
gives the same results.
Ben
------------------------------
Date: Wed, 19 May 2010 16:56:52 -0700
From: sln@netherlands.com
Subject: Re: bit-twiddling on 32-bit machines
Message-Id: <bju8v5l32abguh8rg3e8tmn9cc9b2fgr2f@4ax.com>
On Wed, 19 May 2010 23:44:50 +0100, Ben Morrow <ben@morrow.me.uk> wrote:
>and a C program the does the same operations on a signed 32bit integer
^^ .........^^
This is redundant. There is only unsigned and int.
-sln
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2953
***************************************