Re: [RFC] [discussion] Correctly name the rounding mode and make it an Enum
| From: | Derick Rethans | Date: | Mon, 03 Jun 2024 16:21:22 +0000 |
| Subject: | Re: [RFC] [discussion] Correctly name the rounding mode and make it an Enum | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123492@lists.php.net to get a copy of this message | ||
On Sat, 1 Jun 2024, Gina P. Banyard wrote:
> On Friday, 31 May 2024 at 18:15, Larry Garfield <larry@garfieldtech.com> wrote:
>
> > On Fri, May 31, 2024, at 4:41 PM, Jorg Sowa wrote:
> >
> > > Hey Saki, I like this change. When I was implementing additional
> > > rounding modes for the next PHP version I was initially struggling
> > > with the naming and this change will be helpful.
> > >
> > > I have only one concern about the names
> > >
NegativeInfinity and
> > > PositiveInfinity. They may be too formal from the
> > > user's
> > > perspective. As we already have functions ceil and
> > > floor it's
> > > more intuitive for developers to understand the logic of ceiling
> > > and floor rounding.
> > >
> > > But if voters will prefer those terms then it makes sense to
> > > change the constants implemented in PHP 8.4 (and thus not released
> > > yet) from PHP_ROUND_(CEILING|FLOOR) to
> > > PHP_ROUND_(POSITIVE_INFINITY|NEGATIVE_INFINITY) for
> > > the sake of
> > > consistency.
> >
> > I was confused by those as well. It's not obvious to me what those
> > even do. Do they mean "away from 0"? If not, then I have no clue
> > what they are. :-)
>
> Considering that there are already "Away from 0" and "Towards 0" enum
> cases, the Towards Positive Infinity/Towards Negative Infinity cases
> "obviously" don't mean this.
>
> Towards positive infinity means that for positive numbers you round to
> the integer part plus 1, and for negative numbers you "just" take the
> negative integer part. Similarly, for rounding towards negative
> infinity positive numbers round to "just" the integer part of it, and
> negative numbers round to the negative integer part minus 1.
>
> It should also be noted that ceil/floor is very English specific
> terminology that may not be immediately obvious to non-English
> speakers, thus my preference for using some variation of towards
> positive/negative infinity.
But they're well established in existing PHP features.
cheers,
Derick
--
https://derickrethans.nl | https://xdebug.org | https://dram.io
Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/support
mastodon: @derickr@phpc.social @xdebug@phpc.social