On Sun, Sep 3, 2023 at 5:51 AM Alexandru Pătrănescu <dreal...@gmail.com>
wrote:

> Hi!
>
> On Sun, Sep 3, 2023 at 3:14 PM Tim Düsterhus <t...@bastelstu.be> wrote:
>
> >
> > The RFC mentions already has a section with regard to naming:
> >
> >  > Why not the names PHP_ROUND_UP and PHP_ROUND_DOWN
> >
> > I generally agree with the argument in favor of the names you've chosen.
> > However they are inconsistent with the existing 'PHP_ROUND_HALF_UP' /
> > DOWN constants.
> >
> > I don't want to create extra work for you, but I wonder if additionally
> > one of the following should be done:
> >
> > - Creating PHP_ROUND_HALF_AWAY_FROM_ZERO as an alias for
> > PHP_ROUND_HALF_UP (and likewise for HALF_DOWN).
> >
> >
> I believe consistency is important and using UP for "away from zero" and
> DOWN for "towards zero" sounds good to me. That was so far used
> consistently everywhere, as far as I'm aware.
> Documentation is very clear about what they mean, and you can always think
> that both positive infinity and negative infinity are up while zero is
> down.
>
> Yes, we can have some extra constants for the four ones that contain "up"
> or "down" with "away from zero" and "towards zero", but I find it
> unnecessary.
>

As someone who maintains a math library in PHP that has its own expanded
rounding implementation, I will politely disagree. Away from zero, towards
zero, towards positive infinity, and towards negative infinity are
completely and utterly unambiguous and provide the developer with precise
control over what behavior they want. I don't see a reason to use something
that we KNOW is ambiguous when we're designing it.

This becomes even more important if we ever wanted to provide even more
rounding modes. For instance, a PHP_ROUND_HALF_ALTERNATING would want to
explicitly use positive and negative infinity as its directions most
likely. (The purpose of a "half alternating" mode is to ensure that the
introduced error by rounding many numbers doesn't have a directional bias
by swapping between two modes that round in one direction and then the
other.)

I don't want to complicate this RFC, but I wouldn't mind adding a
PHP_ROUND_STOCHASTIC mode later either. (This mode would round 1.7 to 2 for
70% of executions and 1 for 30% of executions. The purpose of this rounding
mode is to ensure that if you averaged the same number being rounded over
and over, it would average to your original unrounded number, and is used
in many Machine Learning applications.)

Jordan

Reply via email to