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

2023-08-26 Thread Jorg Sowa
I had no idea about your PR Mark. It's pity to see that many improvements
(even simple) like this eventually was not implemented, despite the effort
authors put into.

I have created PR with the change. https://github.com/php/php-src/pull/12056

If you think I should proceed with RFC please let me know. Of course it
will not be merged into the PHP 8.3, but the next version.

Kind regards,
Jorg


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

2023-08-03 Thread Mark Baker

Once upon a many years ago: https://github.com/php/php-src/pull/1658


It will be nice to see it finally get and implementation


On 21/07/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


--
Mark Baker

--
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-23 Thread Jordan LeDoux
On Fri, Jul 21, 2023 at 3:48 PM Jorg Sowa  wrote:

> 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
>

I had to deal with this issue when I was doing the rounding modes for my
math library in PHP. I ended up providing the following rounding modes:

- Half Up (Positive Infinity)
- Half Down (Negative Infinity)
- Half Even
- Half Odd
- Half Zero
- Half Infinity (Closest)
- Half Random (50% chance of either direction)
- Half Alternating (Each subsequent call to round alternates rounding
direction)
- Stochastic (Chance of direction based on proximity... i.e. 1.7 rounds to
2 70% of the time, and rounds to 1 30% of the time)

The only reason I used "Half Up" and "Half Down" is because I also used
"Half Zero" and "Half Infinity" so it was more clear there were
differences. Stochastic is probably the one that sounds weirdest to most
people, but is insanely useful for applications like Machine Learning.

Jordan


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
>