Hi all!
Voting for RFC: Support object type in BCMath has started. Voting ends on 2024-05-16 00:00 GMT.
https://wiki.php.net/rfc/support_object_type_in_bcmath
Regards,
Saki
Hi all!
Voting for RFC: Support object type in BCMath has started. Voting ends on 2024-05-16 00:00 GMT.
https://wiki.php.net/rfc/support_object_type_in_bcmathRegards,
Saki
I voted in favour, as Number being its own type should improve DX and performance for small numbers as we can just store two 64bit integer, one for the integral and another for the fractional part.
However, I have some remarks and questions.
Apologies if these were already brought up, but I haven't gone through the whole 100 long email thread.
- The comparison method should either be called "cmp", or "compare" to align with other extensions, the BC Math function being called bc_comp is weird.
- I don't understand why we are exposing lt, lte, gt, and gte what is the rationale here? Also, the naming is kinda terrible IMHO.
- The "powmod" method should probably be called "powMod"
- Are the existing BCMath function going to be adapted to handle the new Number object or not?
- What is the behaviour when casting a Number object to bool? Does it always cast to true like a "standard" object, or does a Number equal to 0 cast to false?
- Considering the property hook RFC has been accepted, should the $value property be a "virtual" property or not?
Best regards,
Gina P. Banyard
Hi Gina,
I voted in favour, as Number being its own type should improve DX and performance for small numbers as we can just store two 64bit integer, one for the integral and another for the fractional part.
However, I have some remarks and questions.
Apologies if these were already brought up, but I haven't gone through the whole 100 long email thread.
First of all, I have to clear up your misconception.
Number is an object that uses a structure held internally by BCMath. Therefore, the data structure will be the same as the existing BCMath. In other words, supporting object types does not dramatically improve performance or introduce new computational logic.
Even if the data structure is different from the existing one, just two 64-bit values are probably not enough for BCMath.
This may be off-topic, as you may know, BCMath is, in my opinion, a type of what is called BCD (Binary-coded decimal). If we expect to improve performance while maintaining these characteristics, we may want to consider a data type called DPD (densely packed decimal). (I'm doing some refactoring right now, but the changes to the data structure will be quite extensive, so I haven't thought much about it yet.)
- The comparison method should either be called "cmp", or "compare" to align with other extensions, the BC Math function being called bc_comp is weird.
- The "powmod" method should probably be called "powMod"
I named to match existing function names [1]. Admittedly, these names may seem a little strange. However, I didn't change this because it would create a new debate about consistency with existing BC function naming and complicate the RFC.
- I don't understand why we are exposing lt, lte, gt, and gte what is the rationale here? Also, the naming is kinda terrible IMHO.
Does that mean it's unnecessary because it can be compared by operator overload? Or it's unnecessary because comp()
exists?
Regarding naming: These names are also used in Carbon, a php date and time library (these are shorthand name methods) [2]. It is possible to name something like greaterThanOrEqualTo
, but I personally felt it was a little too long, so I shortened it.
Names like these are also used in Laravel's validation rules. Therefore, for PHP users, at least I don't think it's something that makes no sense when see it for the first time.
- Are the existing BCMath function going to be adapted to handle the new Number object or not?
No, that is not considered at this time.
- What is the behaviour when casting a Number object to bool? Does it always cast to true like a "standard" object, or does a Number equal to 0 cast to false?
That's a good topic. I didn't include any mention of this in the RFC because there was no discussion about it. Personally, I like to return a bool value that reflects the internal numerical state, like an int.
However, since I would like to avoid adding such specifications later when voting has already begun, I will use the same as a "standard object" for now. If this RFC is passed, I will additionally propose it in another RFC.
- Considering the property hook RFC has been accepted, should the $value property be a "virtual" property or not?
I think that's probably so. But my understanding is that in this case I don't think it makes any difference to the user.
[1] https://www.php.net/manual/ja/function.bccomp.php
[2] https://carbon.nesbot.com/docs/#api-comparison
Regards,
Saki
Hi Gina,
I voted in favour, as Number being its own type should improve DX and performance for small numbers as we can just store two 64bit integer, one for the integral and another for the fractional part.
However, I have some remarks and questions.
Apologies if these were already brought up, but I haven't gone through the whole 100 long email thread.First of all, I have to clear up your misconception.
Number is an object that uses a structure held internally by BCMath. Therefore, the data structure will be the same as the existing BCMath. In other words, supporting object types does not dramatically improve performance or introduce new computational logic.Even if the data structure is different from the existing one, just two 64-bit values are probably not enough for BCMath.
This may be off-topic, as you may know, BCMath is, in my opinion, a type of what is called BCD (Binary-coded decimal). If we expect to improve performance while maintaining these characteristics, we may want to consider a data type called DPD (densely packed decimal). (I'm doing some refactoring right now, but the changes to the data structure will be quite extensive, so I haven't thought much about it yet.)
If we are not going to use the newfound opaque type to introduce performance optimization for the common cases of small numbers that fit into 64-bit integers, then the value of adding a dedicated object is vastly diminished.
Python is literally doing this sort of optimizations to improve the speed of their arbitrary precision integer type for the common use case of "small integers".
In general, if it cannot fit in a native type then it should continue to use a string, but I would expect the vast majority of cases to fit in a 64-bit integer.
- The comparison method should either be called "cmp", or "compare" to align with other extensions, the BC Math function being called bc_comp is weird.
- The "powmod" method should probably be called "powMod"
I named to match existing function names [1]. Admittedly, these names may seem a little strange. However, I didn't change this because it would create a new debate about consistency with existing BC function naming and complicate the RFC.
I am not sure how using better names complicates an RFC.
- I don't understand why we are exposing lt, lte, gt, and gte what is the rationale here? Also, the naming is kinda terrible IMHO.
Does that mean it's unnecessary because it can be compared by operator overload? Or it's unnecessary because
comp()
exists?Regarding naming: These names are also used in Carbon, a php date and time library (these are shorthand name methods) [2]. It is possible to name something like
greaterThanOrEqualTo
, but I personally felt it was a little too long, so I shortened it.Names like these are also used in Laravel's validation rules. Therefore, for PHP users, at least I don't think it's something that makes no sense when see it for the first time.
In general, I am not sure why there is a need in the first place to expose any of the overloaded operators as methods.
This includes the add/sub/div/mult/mod methods, but I can be convinced that this makes some sense.
However, I see no reason for exposing lt/gt/gte/lte.
I am also not really a fan of the compare and equal methods to be instance methods compared to static methods.
Adding those methods might interfere with any potential RFC that adds an Equatable/Ordable interface to allow userland classes to overload the comparison operators.
I was planning on tackling our rather broken comparison semantics [1] this year, but got distracted by the broken container/offset semantics instead. [2]
As, IMHO, we need to fix the internal object handlers and semantics first before giving this power to userland.
And I feel strongly that using instance methods for overload is the "wrong" way of doing it.
Moreover, if we do provide the option for userland to overload they should, again IMHO, just be able to overload == and <=>, not all the individual comparison operators.
Thus, providing all those methods makes no sense to me.
Moreover, taking inspiration from userland for naming methods because they cannot overload operators seems backwards.
Userland classes, if they want to provide such functionality, must implement a wide range of methods, however an internal class does is not required to do this.
Therefore, I am not really convinced by following suit on userland nomenclature.
- Are the existing BCMath function going to be adapted to handle the new Number object or not?
No, that is not considered at this time.
I am struggling to see a reason for not considering this.
- What is the behaviour when casting a Number object to bool? Does it always cast to true like a "standard" object, or does a Number equal to 0 cast to false?
That's a good topic. I didn't include any mention of this in the RFC because there was no discussion about it. Personally, I like to return a bool value that reflects the internal numerical state, like an int.
However, since I would like to avoid adding such specifications later when voting has already begun, I will use the same as a "standard object" for now. If this RFC is passed, I will additionally propose it in another RFC.
The lack of discussion about this topic is not a good excuse for not having addressed this in the RFC.
This topic should have come up on its own while writing the RFC as this is something that you should have considered, in the same way you have considered how casting to string works.
Moreover, RFC discussions are steered by the content of the RFC, and non-mentioned issues requires other people to consider cases that have not been explicitly address, something that is difficult.
- Considering the property hook RFC has been accepted, should the $value property be a "virtual" property or not?
I think that's probably so. But my understanding is that in this case I don't think it makes any difference to the user.
ACK.
I feel this RFC has been brought to a vote too early, as such I am changing my vote to no.
I am generally in favour of the concept, but there are too many details that are unanswered or didn't even get proper attention for me to feel comfortable with the state of the RFC in question.
Best regards,
Gina P. Banyard
[1] https://github.com/Girgias/php-rfcs/blob/master/comparison-equality-semantics.md
[2] https://github.com/Girgias/php-rfcs/blob/master/container-offset-behaviour.md
Hi
- What is the behaviour when casting a Number object to bool? Does it always cast to true like a "standard" object, or does a Number equal to 0 cast to false?
That's a good topic. I didn't include any mention of this in the RFC because there was no discussion about it. Personally, I like to return a bool value that reflects the internal numerical state, like an int.
However, since I would like to avoid adding such specifications later when voting has already begun, I will use the same as a "standard object" for now. If this RFC is passed, I will additionally propose it in another RFC.
The lack of discussion about this topic is not a good excuse for not having addressed this in the RFC.
This topic should have come up on its own while writing the RFC as this is something that you should have considered, in the same way you have considered how casting to string works.
Moreover, RFC discussions are steered by the content of the RFC, and non-mentioned issues requires other people to consider cases that have not been explicitly address, something that is difficult.I feel this RFC has been brought to a vote too early, as such I am changing my vote to no.
I am generally in favour of the concept, but there are too many details that are unanswered or didn't even get proper attention for me to feel comfortable with the state of the RFC in question.
Thank you for spelling out the feelings that I had towards the RFC but
wasn't able to clearly put into words myself.
Unfortunately I had not seen the announcement about the vote in time,
and wasn't able to give the RFC a final read before the vote. Personally
I also didn't expect a vote yet, because I felt the API surface of the
new class hasn't yet been given a proper thought and discussion,
including all possible edge cases. Most of the discussion I remember
revolved around final vs not-final and how to correctly perform the
rounding / expansion of scale (the latter of which I couldn't comment
on, as numeric programming is not my area of expertise), not the API
surface / the methods that are exposed. As an example, my concern about
the format()
method has been left unresolved.
As such, I'm also voting "no", because I feel like the exposed API is
worse than it could be, but I also support the concept in principle.
Best regards
Tim Düsterhus
- Are the existing BCMath function going to be adapted to handle
the new Number object or not?No, that is not considered at this time.
I am struggling to see a reason for not considering this.
I think that would cause confusion, as BCMath/Number objects do not work
with the global define scale (for good reasons) and bcmath* functions
do.
I think I am in favour of a clean "break" here.
cheers,
Derick
Hi all,
Regarding some of the points, I have decided to address them as th follow-up RFC.
Further discussion will take place in a separate thread.
Regards,
Saki
Hi all,
2024/05/01 17:55、Saki Takamachi saki@sakiot.comのメール:
Hi all!
Voting for RFC: Support object type in BCMath has started. Voting ends on 2024-05-16 00:00 GMT.
https://wiki.php.net/rfc/support_object_type_in_bcmathRegards,
Saki
RFC: Support object type in BCMath was approved with 18 votes in favor and 3 votes against.
https://wiki.php.net/rfc/support_object_type_in_bcmath
Also, the initial value of the implicit rounding mode was determined to be PHP_ROUND_HALF_UP
through a secondary vote.
I'll start implementing it right away, but as I mentioned, we'll be writing a follow-up RFC to address some of the issues. I would like to start a discussion on that right away.
Regards,
Saki
Hi all,
2024/05/01 17:55、Saki Takamachi saki@sakiot.comのメール:
Hi all!
Voting for RFC: Support object type in BCMath has started. Voting ends
on 2024-05-16 00:00 GMT.
https://wiki.php.net/rfc/support_object_type_in_bcmathRegards,
Saki
RFC: Support object type in BCMath was approved with 18 votes in favor and
3 votes against.
https://wiki.php.net/rfc/support_object_type_in_bcmathAlso, the initial value of the implicit rounding mode was determined to be
PHP_ROUND_HALF_UP
through a secondary vote.I'll start implementing it right away, but as I mentioned, we'll be
writing a follow-up RFC to address some of the issues. I would like to
start a discussion on that right away.Regards,
Saki
Hi, Saki!
Am I right, that BCMath\Number
will be implemented in PHP 8.4? I haven't
seen any activity in your PR's recently, that's why I am asking.
--
Best regards,
Valentin
Hi Valentin,
2024/08/25 9:14、Valentin Udaltsov udaltsov.valentin@gmail.comのメール:
Hi all,
2024/05/01 17:55、Saki Takamachi <saki@sakiot.com mailto:saki@sakiot.com>のメール:
Hi all!
Voting for RFC: Support object type in BCMath has started. Voting ends on 2024-05-16 00:00 GMT.
https://wiki.php.net/rfc/support_object_type_in_bcmathRegards,
Saki
RFC: Support object type in BCMath was approved with 18 votes in favor and 3 votes against.
https://wiki.php.net/rfc/support_object_type_in_bcmathAlso, the initial value of the implicit rounding mode was determined to be
PHP_ROUND_HALF_UP
through a secondary vote.I'll start implementing it right away, but as I mentioned, we'll be writing a follow-up RFC to address some of the issues. I would like to start a discussion on that right away.
Regards,
Saki
Hi, Saki!
Am I right, that
BCMath\Number
will be implemented in PHP 8.4? I haven't seen any activity in your PR's recently, that's why I am asking.--
Best regards,
Valentin
Thank you for caring about that, I got hand, foot and mouth disease from my child this month, so I couldn't write much code.
I'm finally feeling better, so I'll hurry up and get my PR ready. (Then there's a ton of test code waiting for me.)
Thanks!
Saki