Re: cvs: php-src(PHP_5_3) /ext/standard math.c

From: Date: Thu, 30 Oct 2008 13:01:47 +0000
Subject: Re: cvs: php-src(PHP_5_3) /ext/standard math.c
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-41574@lists.php.net to get a copy of this message
On 30-Oct-08, at 5:55 AM, Christian Seiler wrote:
1) Internal FPU precision on x86.
Do you have any test cases show the error?
2) Specification problem (which rounding mode should actually be used?) 3) Dividing/multiplying by >= 10^23 is not exact. 4) round (1.255, 2) should give 1.26 but gives 1.25. The FUZZ stuff tries to resolve this issue (but not the other three) but I've come to the conclusion that the FUZZ is actually the wrong solution for the problem.
The current implementation does return 1.26 The proposed solution seems fairly complex and wide-reaching to me, I am also concerned with the overheads it introduces as that was a problem with many in-C implementation libc folks have tried and rejected.
Since I didn't get any reaction on the RFC on internals, I pinged Lukas and Johannes (as they are RMs for PHP 5.3) in private in order to ask whether it was possible to include my proposal in 5.3 (I don't have ZE2 Karma and my patch also needs to change zend_strtod). Lukas and Johannes were concerned about the interopability of my solution of problem (1). So I did some tests on different platforms and operating systems and Lukas and Johannes asked around for other people to do tests, too. I've summarized results of these tests and proposed solution for correct cross-platform floating point arithmetics here: http://www.christian-seiler.de/projekte/fpmath/ I've mailed patches for PHP 5.3 and HEAD to Johannes and Lukas for ZendEngine2 that only address the above issue (1) and do the following: 1) Define some macros for math-related functions that will ensure the function itself always uses double precision. Add configure checks for these macros. 2) Modified zend_strtod and the add/sub/div/mul functions in zend_operators.c to make use of those macros. This ensures that PHP will always use double precision for calculations and math is thus portable. 3) Added a test that determines if the calculations precision is actually correct. The patches for 5.3 and HEAD are found here: http://www.christian-seiler.de/temp/php/2008-10-28-fpu/php-float-precision-5.3.patch http://www.christian-seiler.de/temp/php/2008-10-28-fpu/php-float-precision-6.patch My next step (as discussed with Johannes and Lukas) would have been to apply the Non-ZE2-part of my patch to ext/standard/math.c in 5.3 and HEAD (I don't have separate patches for that yet but they are quite trivial to adapt to the new macros). Now the question is: Where do we go from here? Your commit does not solve all the problems of PHP's round but is at least better than the previous implementation since at least the platform-dependency on whether or not to use the FUZZ is removed. The other problems, however, remain. Christian
Ilia Alshanetsky

« previous php.internals (#41574) next »