ID:               24876
 User updated by:  jeff at tmtrading dot com
 Reported By:      jeff at tmtrading dot com
 Status:           Bogus
 Bug Type:         Math related
 Operating System: Redhat 8.0
 PHP Version:      4CVS-2003-07-30 (stable)
 New Comment:

So you are saying I have to deal with type specific problems even
though PHP is a high level (loosely typed) language?
Who the hell made that decision?
I'm not trying to do complex math or crunch large numbers.  The
language should handle this.


Previous Comments:
------------------------------------------------------------------------

[2003-07-31 13:18:51] [EMAIL PROTECTED]

I tested with Linux. Perhaps you could see the 'problem' better if you
adjusted the precision ini setting. (e.g. ini_set('precision', 32); as
first line in your script..)


------------------------------------------------------------------------

[2003-07-31 13:03:30] jeff at tmtrading dot com

I appears that this problem is bigger than I thought:

http://www.zend.com/lists/php-dev/200206/msg00831.html

Why is nothing being done about this?

------------------------------------------------------------------------

[2003-07-31 12:56:10] jeff at tmtrading dot com

I am going to assue you are testing on windows instead of linux as I
specified.  I downloaded the latest stable snapshot this morning, but
this time I also downloaded the windows version.  Windows returns the
correct result, RedHat linux 8.0 does not.

The linux (and perhaps other unicies) math libraries return different
numbers than windows does.  Thus, if you look at other libraries or
math applications which manipulate double's, they always include some
amount of "fuzz".

I realize that you guys are trying to go through bugs as quickly as
possible, and weeding out the "bogus" ones can be daunting, but please
don't close bugs until you have properly reproduced the potential
problem.

------------------------------------------------------------------------

[2003-07-30 22:16:27] [EMAIL PROTECTED]

Round works fine, 4.045 rounded to 2 digits == 4.05.
Not bug.


------------------------------------------------------------------------

[2003-07-30 19:12:04] jeff at tmtrading dot com

Actually, below would seem to be a better solution.
What I'm trying to point out is that writing a round function in php
and the php's standard funtion give two different answers.  That is
just plain wrong.
There's probably a better way to fix it, but the patch below works for
me (limited testing).

--- php4-STABLE-200307151930/ext/standard/math.c        2003-01-16
07:08:59.000000000 -0700
+++ php4-STABLE-200307301930/ext/standard/math.c        2003-07-30
17:04:50.000000000 -0700
@@ -114,6 +114,7 @@
        zval **value, **precision;
        int places = 0;
        double f, return_val;
+       double fuzz = 0.01;

        if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
                zend_get_parameters_ex(ZEND_NUM_ARGS(), &value,
&precision) == FAILURE) {
@@ -143,9 +144,9 @@

                        return_val *= f;
                        if (return_val >= 0.0)
-                               return_val = floor(return_val + 0.5);
+                               return_val = floor((return_val + fuzz)
+ 0.5);
                        else
-                               return_val = ceil(return_val - 0.5);
+                               return_val = ceil((return_val - fuzz) -
0.5);
                        return_val /= f;

                        RETURN_DOUBLE(return_val);

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/24876

-- 
Edit this bug report at http://bugs.php.net/?id=24876&edit=1

Reply via email to