|
Posted by fritz-bayer@web.de on 10/30/03 11:41
Oli Filth wrote:
> fritz-bayer@web.de said the following on 05/03/2006 11:39:
> > Tim Roberts wrote:
> >>
> >> PHP handles the overflow by throwing away the upper bits, leaving you with
> >> only the bottom 32 bits of the converted value. Perl handles the overflow
> >> by "pegging"; it returns 2^32-1, or 4,294,967,295. That value happens to
> >> have all 32 bit set, so the bitwise "and" returns the second value.
> >>
> >> If you need to handle integers larger than 32-bits in Perl, you can use the
> >> Math::BigInt module to do that.
> >
> > Thanks Tim! Any ideas how I could emulate the overflow, so that I get
> > the same overflow behaviour in perl, maybe by writting a function for
> > it?!
>
>
> Why would you want to do this? Either way, you're not going to get the
> "correct" answer (in terms of mathematically correct).
>
> Your best bet would be to go with the module that Tim suggested (or the
> equivalent (?) in PHP - BCMath). Alternatively, re-think your algorithm
> so that it doesn't require >32-bit numbers. After all, where are these
> numbers going to come from?
>
>
>
> --
> Oli
Hi,
because I have to port the the following function including the
overflow behaviour from php to perl:
//unsigned shift right
function fillWithZeroes($a, $b)
{
$z = hexdec(80000000);
if ($z & $a)
{
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
}
else
{
$a = ($a>>$b);
}
return $a;
}
Navigation:
[Reply to this message]
|