Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22530 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65173 invoked by uid 1010); 20 Mar 2006 08:36:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 65157 invoked from network); 20 Mar 2006 08:36:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2006 08:36:19 -0000 X-Host-Fingerprint: 195.225.34.5 fw01.axit.nl Received: from ([195.225.34.5:24729] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 6D/FE-55982-2896E144 for ; Mon, 20 Mar 2006 03:36:18 -0500 Message-ID: <6D.FE.55982.2896E144@pb1.pair.com> To: internals@lists.php.net References: <33a75ab80603191653tca7f454i8baa71015b5b0373@mail.gmail.com> <441E663D.3050003@album.co.nz> Date: Mon, 20 Mar 2006 09:35:38 +0100 Lines: 163 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-Posted-By: 195.225.34.5 Subject: Re: [PHP-DEV] IntVal(float) Returns Different Values From: r.korving@xit.nl ("Ron Korving") Nonetheless, it's interesting why (int)$int and intval($int) will give different results... Ron "Jasper Bryant-Greene" schreef in bericht news:441E663D.3050003@album.co.nz... > You want the php-general mailing list. This list is for discussing > development of the PHP language and runtime... > > Jasper > > Bruce wrote: >> 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 = -2181087916; >> $AA = (int)$BB; >> $AA = intval($BB); >> >> On some systems, $AA will be int(-2147483648), however, on most systems, >> $AA >> will be int(2113879380), which is the same value truncated at 32 bits. It >> is >> 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 = >> (((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 := Blocks[0]; >> Left := Blocks[1]; >> >> for R := 0 to 3 do begin >> {transform the right side} >> AA := Right; >> BB := Matrix[CKeyBox[Encrypt, R, 0]]; >> CC := Matrix[CKeyBox[Encrypt, R, 1]]; >> DD := Matrix[CKeyBox[Encrypt, R, 2]]; >> >> AA := AA + DD; DD := DD + AA; AA := AA xor (AA shr 7); >> BB := BB + AA; AA := AA + BB; BB := BB xor (BB shl 13); >> CC := CC + BB; BB := BB + CC; CC := CC xor (CC shr 17); >> DD := DD + CC; CC := CC + DD; DD := DD xor (DD shl 9); >> >> AA := AA + DD; DD := DD + AA; AA := AA xor (AA shr 3); >> BB := BB + AA; BB := BB xor (BB shl 7); >> CC := CC + BB; >> CC := CC xor (DD shr 15); >> DD := DD + CC; >> DD := DD xor (DD shl 11); >> >> Work := Left xor DD; >> Left := Right; >> Right := Work; >> end; >> >> Blocks[0] := Left; >> Blocks[1] := Right; >> end; >> >> Here is my PHP port: >> >> > function zeroFill($a, $b) >> { >> $z = hexdec(80000000); >> if ($z & $a) >> { >> $a >>= 1; >> $a &= (~ $z); >> $a |= 0x40000000; >> $a >>= ($b-1); >> } >> else >> { >> $a >>= $b; >> } >> return $a; >> } >> >> function MixBlock($AKey, &$ACode, $Encrypt) >> { >> $CKeyBox = array(array(3, 2, 0), array(1, 0, 2), array(2, 1, 3), >> array(0, >> 3, 1)); >> >> $Right = $ACode[0]; >> $Left = $ACode[1]; >> >> for ($R=0; $R<=3; $R++) >> { >> $AA = $Right; >> if ($Encrypt) >> { >> $BB = $AKey[$CKeyBox[$R][0]]; >> $CC = $AKey[$CKeyBox[$R][1]]; >> $DD = $AKey[$CKeyBox[$R][2]]; >> } >> else >> { >> $BB = $AKey[$CKeyBox[3-$R][0]]; >> $CC = $AKey[$CKeyBox[3-$R][1]]; >> $DD = $AKey[$CKeyBox[3-$R][2]]; >> } >> >> $AA = (int)$AA + (int)$DD; >> $DD = (int)$DD + (int)$AA; >> $AA = (int)$AA ^ zeroFill($AA, 7); >> $BB = (int)$BB + (int)$AA; >> $AA = (int)$AA + (int)$BB; >> >> $BB = (int)$BB ^ ((int)$BB << 13); >> $CC = (int)$CC + (int)$BB; $BB = (int)$BB + (int)$CC; >> $CC = (int)$CC ^ zeroFill($CC, 17); >> $DD = (int)$DD + (int)$CC; $CC = (int)$CC + (int)$DD; >> $DD = (int)$DD ^ ((int)$DD << 9); >> >> $AA = (int)$AA + (int)$DD; $DD = (int)$DD + (int)$AA; >> $AA = (int)$AA ^ zeroFill($AA, 3); >> $BB = (int)$BB + (int)$AA; >> $BB = (int)$BB ^ (int)((int)$BB << 7); >> $CC = (int)$CC + (int)$BB; >> $CC = (int)$CC ^ zeroFill($DD, 15); >> $DD = (int)$DD + (int)$CC; >> $DD = (int)$DD ^ (int)((int)$DD << 11); >> >> $Work = $Left ^ $DD; >> $Left = $Right; >> $Right = $Work; >> } >> >> $ACode[0] = $Left; >> $ACode[1] = $Right; >> } >> ?> >>