RE: [PHP-DEV] Re: #19259 [Csd-Ctl]: sort-functions don't work
-Original Message- From: Michael Mauch [mailto:[EMAIL PROTECTED]] Sent: Saturday, November 16, 2002 4:29 PM To: [EMAIL PROTECTED] Subject: [PHP-DEV] Re: #19259 [Csd-Ctl]: sort-functions don't work I wrote: These test results scared me as well, but it looks like this array test itsself is flawed: it relies on the fact that integers automatically wrap around to negative values at INT_MAX (=2147483647 on 32 bit machines). Attaching a patch for the array test: I changed the array in data.inc to have only normal values (1000 and -1000) instead of 2147483647 and -2147483647, and used the output of the tests on a 32 bit Linux machine to be the expected result. With the patch, all three tests PASSed on the 64 bit Tru64 machine. So array sorting is fortunately not broken again on Tru64. Great! It would be nice if someone with enough karma apply this patch. Regards, Sebastian Nohn -- [EMAIL PROTECTED] - http://www.nohn.net/ PGP Key Available - Did I help you? Consider a gift: http://www.amazon.de/exec/obidos/wishlist/3HYH6NR8ZI0WI/ -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: #19259 [Csd-Ctl]: sort-functions don't work
Thanks it looks good - applied. marcus At 16:29 16.11.2002, Michael Mauch wrote: I wrote: These test results scared me as well, but it looks like this array test itsself is flawed: it relies on the fact that integers automatically wrap around to negative values at INT_MAX (=2147483647 on 32 bit machines). Attaching a patch for the array test: I changed the array in data.inc to have only normal values (1000 and -1000) instead of 2147483647 and -2147483647, and used the output of the tests on a 32 bit Linux machine to be the expected result. With the patch, all three tests PASSed on the 64 bit Tru64 machine. So array sorting is fortunately not broken again on Tru64. Regards... Michael diff -r -u ../php-cvs/php4/ext/standard/tests/array/001.phpt ext/standard/tests/array/001.phpt --- ../php-cvs/php4/ext/standard/tests/array/001.phpt Sat Nov 9 11:42:49 2002 +++ ext/standard/tests/array/001.phpt Sat Nov 16 16:08:01 2002 @@ -57,7 +57,7 @@ int(27) [3]= string(4) test - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -113,7 +113,7 @@ int(27) int(3) string(4) test -string(11) -2147483647 +string(5) -1000 array(2) { [0]= string(6) banana diff -r -u ../php-cvs/php4/ext/standard/tests/array/002.phpt ext/standard/tests/array/002.phpt --- ../php-cvs/php4/ext/standard/tests/array/002.phpt Sat Nov 9 11:42:49 2002 +++ ext/standard/tests/array/002.phpt Sat Nov 16 16:07:14 2002 @@ -24,16 +24,43 @@ var_dump ($data); } +echo Unsorted data:\n; +var_dump ($data); foreach (array ('arsort', 'asort', 'krsort', 'ksort', 'rsort', 'sort') as $test_function) { test_sort ($test_function, $data); } ? --EXPECT-- --- Testing arsort() -- +Unsorted data: +array(8) { + [0]= + string(3) PHP + [17]= + string(27) PHP: Hypertext Preprocessor + [5]= + string(4) Test + [test]= + int(27) + [1000]= + string(4) test + [-1000]= + array(2) { +[0]= +string(6) banana +[1]= +string(6) orange + } + [1001]= + string(6) monkey + [16777216]= + float(-0.33) +} + + -- Testing arsort() -- No second argument: array(8) { - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -42,9 +69,9 @@ } [test]= int(27) - [2147483647]= + [1000]= string(4) test - [-2147483648]= + [1001]= string(6) monkey [5]= string(4) Test @@ -57,7 +84,7 @@ } Using SORT_REGULAR: array(8) { - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -66,9 +93,9 @@ } [test]= int(27) - [2147483647]= + [1000]= string(4) test - [-2147483648]= + [1001]= string(6) monkey [5]= string(4) Test @@ -83,7 +110,7 @@ array(8) { [test]= int(27) - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -94,20 +121,20 @@ string(3) PHP [17]= string(27) PHP: Hypertext Preprocessor - [-2147483648]= + [1001]= string(6) monkey [5]= string(4) Test - [2147483647]= + [1000]= string(4) test [16777216]= float(-0.33) } Using SORT_STRING array(8) { - [2147483647]= + [1000]= string(4) test - [-2147483648]= + [1001]= string(6) monkey [5]= string(4) Test @@ -115,7 +142,7 @@ string(27) PHP: Hypertext Preprocessor [0]= string(3) PHP - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -139,13 +166,13 @@ string(27) PHP: Hypertext Preprocessor [5]= string(4) Test - [-2147483648]= + [1001]= string(6) monkey - [2147483647]= + [1000]= string(4) test [test]= int(27) - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -163,13 +190,13 @@ string(27) PHP: Hypertext Preprocessor [5]= string(4) Test - [-2147483648]= + [1001]= string(6) monkey - [2147483647]= + [1000]= string(4) test [test]= int(27) - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -181,9 +208,9 @@ array(8) { [16777216]= float(-0.33) - [-2147483648]= + [1001]= string(6) monkey - [2147483647]= + [1000]= string(4) test [5]= string(4) Test @@ -191,7 +218,7 @@ string(27) PHP: Hypertext Preprocessor [0]= string(3) PHP - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -207,7 +234,7 @@ float(-0.33) [test]= int(27) - [-2147483647]= + [-1000]= array(2) { [0]= string(6) banana @@ -220,19 +247,21 @@ string(27) PHP: Hypertext Preprocessor [5]= string(4) Test - [-2147483648]= + [1001]= string(6) monkey - [2147483647]= + [1000]= string(4) test } -- Testing krsort() -- No second argument: array(8) { - [2147483647]= - string(4) test [16777216]= float(-0.33) + [1001]= + string(6) monkey + [1000]= + string(4) test [17]= string(27) PHP: Hypertext Preprocessor [5]= @@ -241,46 +270,46 @@ int(27) [0]= string(3) PHP - [-2147483647]= + [-1000]=
Re: [PHP-DEV] Re: #19259 [Csd-Ctl]: sort-functions don't work
Marcus Börger [EMAIL PROTECTED] wrote: Thanks it looks good - applied. Thanks, great. While we're at it, there's another test which fails on 64 bit machines and can easily be fixed: var_dump float test [ext/standard/tests/general_functions/008.phpt] This test fails because 123456789012 and 1234567890120 are PHP integers on 64 bit machines: EXPECTED OUTPUT [...] [11]= float(123456789012) [12]= float(1234567890120) ACTUAL OUTPUT [...] [11]= int(123456789012) [12]= int(1234567890123) The fix: --- ext/standard/tests/general_functions/008.phpt~ Wed Aug 21 03:27:56 2002 +++ ext/standard/tests/general_functions/008.phpt Sun Nov 10 22:50:29 2002 @@ -5,7 +5,7 @@ --FILE-- ?php // this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,1234567890123,12345678901234567890)); +var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,(float)1234567890123,(float)12345678901234567890)); ? --EXPECT-- array(14) { Regards... Michael -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: #19259 [Csd-Ctl]: sort-functions don't work
Could you try the following patch instead? cvs -z3 -q diff 008.phpt (in directory S:\php4-HEAD\ext\standard\tests\general_functions) Index: 008.phpt === RCS file: /repository/php4/ext/standard/tests/general_functions/008.phpt,v retrieving revision 1.1 diff -u -r1.1 008.phpt --- 008.phpt21 Aug 2002 01:27:56 - 1.1 +++ 008.phpt16 Nov 2002 19:29:06 - @@ -5,7 +5,7 @@ --FILE-- ?php // this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,1234567890123,12345678901234567890)); +var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012.0,1234567890123.0,12345678901234567890)); ? --EXPECT-- array(14) { At 20:17 16.11.2002, Michael Mauch wrote: Marcus Börger [EMAIL PROTECTED] wrote: Thanks it looks good - applied. Thanks, great. While we're at it, there's another test which fails on 64 bit machines and can easily be fixed: var_dump float test [ext/standard/tests/general_functions/008.phpt] This test fails because 123456789012 and 1234567890120 are PHP integers on 64 bit machines: EXPECTED OUTPUT [...] [11]= float(123456789012) [12]= float(1234567890120) ACTUAL OUTPUT [...] [11]= int(123456789012) [12]= int(1234567890123) The fix: --- ext/standard/tests/general_functions/008.phpt~ Wed Aug 21 03:27:56 2002 +++ ext/standard/tests/general_functions/008.phpt Sun Nov 10 22:50:29 2002 @@ -5,7 +5,7 @@ --FILE-- ?php // this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,1234567890123,12345678901234567890)); +var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,(float)1234567890123,(float)12345678901234567890)); ? --EXPECT-- array(14) { Regards... Michael -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: #19259 [Csd-Ctl]: sort-functions don't work
Ups one missing: cvs -z3 -q diff 008.phpt (in directory S:\php4-HEAD\ext\standard\tests\general_functions\) Index: 008.phpt === RCS file: /repository/php4/ext/standard/tests/general_functions/008.phpt,v retrieving revision 1.1 diff -u -r1.1 008.phpt --- 008.phpt21 Aug 2002 01:27:56 - 1.1 +++ 008.phpt16 Nov 2002 19:31:34 - @@ -5,7 +5,7 @@ --FILE-- ?php // this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,1234567890123,12345678901234567890)); +var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012.0,1234567890123.0,12345678901234567890.0)); ? --EXPECT-- array(14) { At 20:29 16.11.2002, Marcus Börger wrote: Could you try the following patch instead? cvs -z3 -q diff 008.phpt (in directory S:\php4-HEAD\ext\standard\tests\general_functions) Index: 008.phpt === RCS file: /repository/php4/ext/standard/tests/general_functions/008.phpt,v retrieving revision 1.1 diff -u -r1.1 008.phpt --- 008.phpt21 Aug 2002 01:27:56 - 1.1 +++ 008.phpt16 Nov 2002 19:29:06 - @@ -5,7 +5,7 @@ --FILE-- ?php // this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,1234567890123,12345678901234567890)); +var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012.0,1234567890123.0,12345678901234567890)); ? --EXPECT-- array(14) { At 20:17 16.11.2002, Michael Mauch wrote: Marcus Börger [EMAIL PROTECTED] wrote: Thanks it looks good - applied. Thanks, great. While we're at it, there's another test which fails on 64 bit machines and can easily be fixed: var_dump float test [ext/standard/tests/general_functions/008.phpt] This test fails because 123456789012 and 1234567890120 are PHP integers on 64 bit machines: EXPECTED OUTPUT [...] [11]= float(123456789012) [12]= float(1234567890120) ACTUAL OUTPUT [...] [11]= int(123456789012) [12]= int(1234567890123) The fix: --- ext/standard/tests/general_functions/008.phpt~ Wed Aug 21 03:27:56 2002 +++ ext/standard/tests/general_functions/008.phpt Sun Nov 10 22:50:29 2002 @@ -5,7 +5,7 @@ --FILE-- ?php // this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,1234567890123,12345678901234567890)); +var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.123,123456789012,(float)1234567890123,(float)12345678901234567890)); ? --EXPECT-- array(14) { Regards... Michael -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php