Re: [PHP-DEV] [RFC] Make the GMP class final

2024-06-29 Thread Barney Laurance
On 29/06/2024 16:55, Ben Ramsey wrote: If this RFC passes to make the \GMP class final, and your RFC passes to allow extending the \GMP class, then I think we’re in a sort of weird limbo state. Presumably in that case whichever RFC passes last would have to take precedence. The community is al

Re: [PHP-DEV] Add bcdivmod() to BCMath

2024-06-25 Thread Barney Laurance
On Tue, 25 Jun 2024 17:29:58 +0100 Saki Takamachi wrote --- > > Also, it is not practical to record the remainder in the Number object > resulting from the division. This is because there can be objects whose > division results are equal but whose remainders are different. >

Re: [PHP-DEV] Add bcdivmod() to BCMath

2024-06-25 Thread Barney Laurance
On Tue, 25 Jun 2024 10:11:10 +0100 Saki Takamachi wrote --- > Hi internals, > > I've been working on improving performance of BCMath lately, and I found > that I can get the div and mod in one calculation. This is obviously faster > than calculating it twice separately. > > Do

Re: [PHP-DEV] [Discussion] "Internal" attribute and warning

2024-05-18 Thread Barney Laurance
On 18/05/2024 15:00, Robert Landers wrote: Hello internals, I've been thinking about having an "internal" attribute that will emit a warning if called from outside it's left-most namespace. Hello Robert, It's worth looking at the prior art on this - the @internal annotation from PHPDoc, and

Re: [PHP-DEV] Native decimal scalar support and object types in BcMath - do we want both?

2024-04-08 Thread Barney Laurance
On 2024-04-08 12:17, Arvids Godjuks wrote: Why not have decimal be represented as 2 64-bit ints at the engine level Just to clarify this point, what's the formula to convert back and forth between a decimal and two integers? Are you thinking like scientific notation: decimal = coefficient *

Re: [PHP-DEV] Native decimal scalar support and object types in BcMath - do we want both?

2024-04-07 Thread Barney Laurance
On 07/04/2024 11:07, Rowan Tommins [IMSoP] wrote: On 7 April 2024 01:32:29 BST, Jordan LeDoux wrote: Internals is just volunteers. The people working on BCMath are doing that because they want to, the people working on scalar decimal stuff are doing that because they want to, and there's no p

[PHP-DEV] Native decimal scalar support and object types in BcMath - do we want both?

2024-04-06 Thread Barney Laurance
Hello, There are currently two proposals being discussed - /native decimal scalar type support/ and /Support object type in BCMath/ I've been getting involved in the discussion for the BCMath proposal, but not paying as much attention to the native decimal thread. But these seem like very s

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-05 Thread Barney Laurance
On 05/04/2024 09:37, Saki Takamachi wrote: Hi Barney, Ah ok. Maybe that's the standard way internal classes are written, and we can consider it generally an error for a child class to override the constructor without calling `parent::__construct()`. I know tools warn users not to forget the

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-05 Thread Barney Laurance
On 05/04/2024 10:48, Tim Düsterhus wrote: Your `Money` example would allow for unsound and/or non-sense behavior, such as:     $fiveEuros = new Money(5, 'EUR');     $tenDollars = new Money(10, 'EUR');     $what = $fiveEuros + $tenDollars; What would you expect to be in $what? A `BcMath\Nu

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-04 Thread Barney Laurance
On 05/04/2024 01:20, Saki Takamachi wrote: I don't think it will be possible to make a good Money class as a child of this. BcNum is a read-only class, so if the constructor of BcNum is final then the child class won't be able to take the currency as a constructor param, and won't be able to

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-04 Thread Barney Laurance
On 04/04/2024 22:10, Jordan LeDoux wrote: On Thu, Apr 4, 2024 at 1:59 PM Barney Laurance wrote: Hi again, On 27/03/2024 00:40, Saki Takamachi wrote: Do we also need `toFloat` and `toInt` functions? Seems like using explicit functions will be safer than casting. For

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-04 Thread Barney Laurance
On 04/04/2024 01:54, Jordan LeDoux wrote: On Tue, Apr 2, 2024 at 5:43 PM Saki Takamachi wrote: If make a class final, users will not be able to add arbitrary methods, so I think making each method final. Although it is possible to completely separate behavior between method and o

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-04 Thread Barney Laurance
Hi again, On 27/03/2024 00:40, Saki Takamachi wrote: Do we also need `toFloat` and `toInt` functions? Seems like using explicit functions will be safer than casting. For toInt I'd expect an exception if the value is outside the range of possible ints. For toFloat it might be nice to have a fl

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-03 Thread Barney Laurance
On 03/04/2024 01:42, Saki Takamachi wrote: If make a class final, users will not be able to add arbitrary methods, so I think making each method final. Right, if a class is not final but has only final methods (including constructor) and no protected properties then it allows people to exten

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-04-02 Thread Barney Laurance
On 2024-04-02 12:26, Saki Takamachi wrote: Also, an idea occurred to me while reading your comments. The current assumption is that a Number always holds a single value. How if we made it so that it held two values? They are the numerator and the denominator. Then we'd have a rational number,

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-03-26 Thread Barney Laurance
On 2024-03-24 13:13, Saki Takamachi wrote: I want to start the discussion on the PHP RFC: Support object type in BCMath. Do we also need `toFloat` and `toInt` functions? Seems like using explicit functions will be safer than casting. For toInt I'd expect an exception if the value is outside

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-03-26 Thread Barney Laurance
On 2024-03-26 11:35, Saki Takamachi wrote: **I immediately reflected the above two points in my RFC** :D Thanks, looks good. One more suggestion - might it be worth adding a `format` function to the new BcNum class? This would be similar to the existing number_format function, but would avo

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-03-26 Thread Barney Laurance
On 24/03/2024 13:13, Saki Takamachi wrote: I want to start the discussion on the PHP RFC: Support object type in BCMath. https://wiki.php.net/rfc/support_object_type_in_bcmath One more suggestion - might it be worth adding a `format` function to the new BcNum class? This would be similar to t

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-03-25 Thread Barney Laurance
On 24/03/2024 13:13, Saki Takamachi wrote: I want to start the discussion on the PHP RFC: Support object type in BCMath. I work on OLTP application using BCMath for money, and I would like to refactor to value objects (although we could also convert to using ints), so this is very relevant to

Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath

2024-03-25 Thread Barney Laurance
On 24/03/2024 13:13, Saki Takamachi wrote: I want to start the discussion on the PHP RFC: Support object type in BCMath. I suggest renaming `setScale` to `withScale`. Although the docs will make clear that the object is immutable, `set` is associated with mutation and might be confusing. `wit

Re: [PHP-DEV] Supporting object types in BCMath

2024-03-16 Thread Barney Laurance
On 16/03/2024 05:22, Saki Takamachi wrote: Yet another idea is to also support immutable objects, like DateTime. e.g. ``` $num1 = new BcNum('1.235'); $num1imm = new BcNumImmutable('1.235'); $num2 = new BcNum('2.001'); $num1result = $num1->add($num2); $num1immResult = $num1imm->add($num2); I wou