RE: [PHP-DEV] [RFC] [PATCH] Rounding in PHP
| From: | Jonathan Bond-Caron | Date: | Thu, 04 Sep 2008 11:39:34 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] [PATCH] Rounding in PHP | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40248@lists.php.net to get a copy of this message | ||
On Thu Aug 28 01:47 PM, Christian Seiler wrote:
> Hi again,
>
>> A few weeks ago I wrote quite a long posting to internals@ that tried
>> to clarify the situation on the round() function in PHP. I was asked
>> to write it up as an RFC in the wiki, which I have done:
>>
>> http://wiki.php.net/rfc/rounding
>
> Since there has been no reaction so far to my proposal (besides the
> help from Hannes and Pierre for the Win32 build dependencies, thanks
> for that btw.), I'd like to know why? Am I talking gibberish and my
> proposal is hard to understand? Or have I simply chosen a topic that
> many do not consider worthwhile investing that amount of energy into?
> Or is it something else?
For the record, I was very excited to see your proposal and the work you've done.
I'm not a PHP dev so I can't comment on the patch, maybe there might be a performance
concern?
I don't know either the history of the 'rounding fuzz', but there's definitely
space for improvement... The problem naturally isn't with floats but that the round() function
is very misleading. My opinion is the rounding precision should be removed or fixed since it
doesn't work "as expected". i.e. javascript, there's no precision: Math.round()
"
Nevertheless, what could be discussed separately is the introduction of a new type that
automatically uses an arbitrary precision library internally, since writing $a * $b is much more
natural than e.g. bcmul($a, $b). This, however, goes far beyond the scope of this proposal.
"
I'm all for this... maybe something like this:
// within some 'numeric' precision
$a = (numeric)2;
$b = (numeric)0.5;
$mult = $a * $b;
echo $mult;// 1 (numeric)
echo (2.5 == $a + $b); // true
echo (2.5 === $a + $b); // false
echo ((numeric)2.5 === $a + $b); // true