Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22527 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73036 invoked by uid 1010); 20 Mar 2006 00:53:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 73021 invoked from network); 20 Mar 2006 00:53:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2006 00:53:33 -0000 X-Host-Fingerprint: 64.233.162.201 zproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.162.201:48216] helo=zproxy.gmail.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id F3/98-55982-C0DFD144 for ; Sun, 19 Mar 2006 19:53:32 -0500 Received: by zproxy.gmail.com with SMTP id 8so900410nzo for ; Sun, 19 Mar 2006 16:53:30 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=VEmImtrWUcAMH4mgrhlWpWr3FqwGKM/z9e/yEY8ecFvSXrl6tFK1vB1Yrg5qAr90/ywaSpih2n1jwx6MRA3cDoOLQoXIpzKz2N7Ty8VY/3bywY9QwBCghXIcXdFDV3HnNgRfaZ5MSm4Baji9VioQwbcUzW5uANuXH/rs3nspQsQ= Received: by 10.37.12.24 with SMTP id p24mr477831nzi; Sun, 19 Mar 2006 16:53:30 -0800 (PST) Received: by 10.36.177.16 with HTTP; Sun, 19 Mar 2006 16:53:30 -0800 (PST) Message-ID: <33a75ab80603191653tca7f454i8baa71015b5b0373@mail.gmail.com> Date: Sun, 19 Mar 2006 19:53:30 -0500 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5005_8814453.1142816010317" Subject: IntVal(float) Returns Different Values From: bvanderw@gmail.com (Bruce) ------=_Part_5005_8814453.1142816010317 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I am having trouble porting some code originally written in Borland Delphi to PHP. The Delphi code expects certain behavior on integer overflows that = I can only duplicate on some PHP systems. For example: $BB =3D -2181087916; $AA =3D (int)$BB; $AA =3D intval($BB); On some systems, $AA will be int(-2147483648), however, on most systems, $A= A will be int(2113879380), which is the same value truncated at 32 bits. It i= s this latter behavior that I need to properly port the Delphi code. Can someone suggest a way to do this that is consistent on all platforms? For reference, I am attaching the Delphi code and my PHP port. Thanks... --Bruce {quick (block) mixer routine} procedure MixBlock(const Matrix : T128bit; var Block; Encrypt : Boolean); const CKeyBox : array [False..True, 0..3, 0..2] of LongInt =3D (((0, 3, 1), (2, 1, 3), (1, 0, 2), (3, 2, 0)), ((3, 2, 0), (1, 0, 2), (2, 1, 3), (0, 3, 1))); var Blocks : array [0..1] of LongInt absolute Block; Work : LongInt; Right : LongInt; Left : LongInt; R : LongInt; AA, BB : LongInt; CC, DD : LongInt; begin Right :=3D Blocks[0]; Left :=3D Blocks[1]; for R :=3D 0 to 3 do begin {transform the right side} AA :=3D Right; BB :=3D Matrix[CKeyBox[Encrypt, R, 0]]; CC :=3D Matrix[CKeyBox[Encrypt, R, 1]]; DD :=3D Matrix[CKeyBox[Encrypt, R, 2]]; AA :=3D AA + DD; DD :=3D DD + AA; AA :=3D AA xor (AA shr 7); BB :=3D BB + AA; AA :=3D AA + BB; BB :=3D BB xor (BB shl 13); CC :=3D CC + BB; BB :=3D BB + CC; CC :=3D CC xor (CC shr 17); DD :=3D DD + CC; CC :=3D CC + DD; DD :=3D DD xor (DD shl 9); AA :=3D AA + DD; DD :=3D DD + AA; AA :=3D AA xor (AA shr 3); BB :=3D BB + AA; BB :=3D BB xor (BB shl 7); CC :=3D CC + BB; CC :=3D CC xor (DD shr 15); DD :=3D DD + CC; DD :=3D DD xor (DD shl 11); Work :=3D Left xor DD; Left :=3D Right; Right :=3D Work; end; Blocks[0] :=3D Left; Blocks[1] :=3D Right; end; Here is my PHP port: >=3D 1; $a &=3D (~ $z); $a |=3D 0x40000000; $a >>=3D ($b-1); } else { $a >>=3D $b; } return $a; } function MixBlock($AKey, &$ACode, $Encrypt) { $CKeyBox =3D array(array(3, 2, 0), array(1, 0, 2), array(2, 1, 3), array(= 0, 3, 1)); $Right =3D $ACode[0]; $Left =3D $ACode[1]; for ($R=3D0; $R<=3D3; $R++) { $AA =3D $Right; if ($Encrypt) { $BB =3D $AKey[$CKeyBox[$R][0]]; $CC =3D $AKey[$CKeyBox[$R][1]]; $DD =3D $AKey[$CKeyBox[$R][2]]; } else { $BB =3D $AKey[$CKeyBox[3-$R][0]]; $CC =3D $AKey[$CKeyBox[3-$R][1]]; $DD =3D $AKey[$CKeyBox[3-$R][2]]; } $AA =3D (int)$AA + (int)$DD; $DD =3D (int)$DD + (int)$AA; $AA =3D (int)$AA ^ zeroFill($AA, 7); $BB =3D (int)$BB + (int)$AA; $AA =3D (int)$AA + (int)$BB; $BB =3D (int)$BB ^ ((int)$BB << 13); $CC =3D (int)$CC + (int)$BB; $BB =3D (int)$BB + (int)$CC; $CC =3D (int)$CC ^ zeroFill($CC, 17); $DD =3D (int)$DD + (int)$CC; $CC =3D (int)$CC + (int)$DD; $DD =3D (int)$DD ^ ((int)$DD << 9); $AA =3D (int)$AA + (int)$DD; $DD =3D (int)$DD + (int)$AA; $AA =3D (int)$AA ^ zeroFill($AA, 3); $BB =3D (int)$BB + (int)$AA; $BB =3D (int)$BB ^ (int)((int)$BB << 7); $CC =3D (int)$CC + (int)$BB; $CC =3D (int)$CC ^ zeroFill($DD, 15); $DD =3D (int)$DD + (int)$CC; $DD =3D (int)$DD ^ (int)((int)$DD << 11); $Work =3D $Left ^ $DD; $Left =3D $Right; $Right =3D $Work; } $ACode[0] =3D $Left; $ACode[1] =3D $Right; } ?> ------=_Part_5005_8814453.1142816010317--