Re: [PHP-DEV] Introducing 2 new modes to round function

2023-07-21 Thread Jorg Sowa
Thank you for your suggestions. I added two remaining modes and I think
it's complete now.

I changed the names to `PHP_ROUND_CEILING` and `PHP_ROUND_FLOOR` to be
consisted with rounding modes in number_format() function. I'm not sure
about `PHP_TOWARD_ZERO` and 'PHP_AWAY_FROM_ZERO` as in there it's
`ROUND_DOWN` and `ROUND_UP`, which I also find too vague.

However, I could find names UP and DOWN in other documentations. And sadly
it refers to away from zero and toward zero, so there is big mismatch in
existing naming.

https://developer.apple.com/documentation/foundation/numberformatter/roundingmode/down
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/math/RoundingMode.html

Kind regards,
Jorg



Re: [PHP-DEV] Introducing 2 new modes to round function

2023-07-21 Thread Marco Pivetta
On Fri, 21 Jul 2023, 22:05 Dusk,  wrote:

> On Jul 21, 2023, at 12:38, Marco Pivetta  wrote:
> > Hey Jorg,
> >
> > What is the reason for using this over these?
> >
> > * https://www.php.net/manual/en/function.ceil.php
> > * https://www.php.net/manual/en/function.floor.php
>
> floor() and ceil() don't have a $precision parameter.
>

Thanks for clarifying 

>


Re: [PHP-DEV] Introducing 2 new modes to round function

2023-07-21 Thread Andreas Heigl
On 21 July 2023 21:38:03 CEST, Marco Pivetta  wrote:
> Hey Jorg,
> 
> What is the reason for using this over these?
> 
>  * https://www.php.net/manual/en/function.ceil.php
>  * https://www.php.net/manual/en/function.floor.php
> 
>
Hey Marco

floor and ceil convert a float to the next int.

round can also convert to the next decimal-,level.

round(16, -1) will round to 20 whereas round(12, -1) will be 10. And tuere's no 
way currently to make the first one 10 and the second one 20.

Cheers

Andreas
> 
> On Fri, 21 Jul 2023, 21:26 Jorg Sowa,  wrote:
> 
> > Hello internals!
> >
> > I would like to propose introducing two new modes to the function
> > `round()`: PHP_ROUND_DOWN and PHP_ROUND_UP.
> >
> > Those modes are highly requested as you can see by the comments on round
> > documentation page. First comment mentioning about those modes has 309
> > votes as of today. Introducing those 2 modes would be complementing to the
> > rounding in this function.
> >
> > Round documentation: https://www.php.net/manual/en/function.round.php
> > My implementation: https://github.com/php/php-src/pull/11741
> >
> > I'm not sure if such minor improvement requires RFC, but as someone may
> > have some concerns I create this thread to get your feedback.
> >
> > Kind regards,
> > Jorg
> >


--
Andreas Heigl

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] Introducing 2 new modes to round function

2023-07-21 Thread Dusk
On Jul 21, 2023, at 12:38, Marco Pivetta  wrote:
> Hey Jorg,
> 
> What is the reason for using this over these?
> 
> * https://www.php.net/manual/en/function.ceil.php
> * https://www.php.net/manual/en/function.floor.php

floor() and ceil() don't have a $precision parameter.

What could be even more useful, however, would be to add modes which always 
round towards / away from zero. I suspect the commenter intending to use these 
modes in accounting would prefer these semantics over an implementation (like 
theirs) which always rounds to numerically higher / lower values.

It might also be appropriate to use more specific terminology for these modes, 
e.g. PHP_ROUND_FLOOR/_CEIL and PHP_ROUND_TO_ZERO/_AWAY_FROM_ZERO, rather than 
the ambiguous PHP_ROUND_DOWN.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] Introducing 2 new modes to round function

2023-07-21 Thread Marco Pivetta
Hey Jorg,

What is the reason for using this over these?

 * https://www.php.net/manual/en/function.ceil.php
 * https://www.php.net/manual/en/function.floor.php



On Fri, 21 Jul 2023, 21:26 Jorg Sowa,  wrote:

> Hello internals!
>
> I would like to propose introducing two new modes to the function
> `round()`: PHP_ROUND_DOWN and PHP_ROUND_UP.
>
> Those modes are highly requested as you can see by the comments on round
> documentation page. First comment mentioning about those modes has 309
> votes as of today. Introducing those 2 modes would be complementing to the
> rounding in this function.
>
> Round documentation: https://www.php.net/manual/en/function.round.php
> My implementation: https://github.com/php/php-src/pull/11741
>
> I'm not sure if such minor improvement requires RFC, but as someone may
> have some concerns I create this thread to get your feedback.
>
> Kind regards,
> Jorg
>


[PHP-DEV] Introducing 2 new modes to round function

2023-07-21 Thread Jorg Sowa
Hello internals!

I would like to propose introducing two new modes to the function
`round()`: PHP_ROUND_DOWN and PHP_ROUND_UP.

Those modes are highly requested as you can see by the comments on round
documentation page. First comment mentioning about those modes has 309
votes as of today. Introducing those 2 modes would be complementing to the
rounding in this function.

Round documentation: https://www.php.net/manual/en/function.round.php
My implementation: https://github.com/php/php-src/pull/11741

I'm not sure if such minor improvement requires RFC, but as someone may
have some concerns I create this thread to get your feedback.

Kind regards,
Jorg