---- 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 you think there's a demand for this feature?
 > 
 > e.g.
 > ```
 > [$quot, $rem] = bcdivmod('123', '2');
 > // $quot is '61', $rem is '1'
 > ```
 > 
 > The naming and return value scheme is inspired by Python and Ruby.
 > 
 > Of course, if this is added, equivalent functionality will be added to the 
 > Number class.

I'm wondering whether this needs to be a change to the API, or if it might be 
better implemented as a purely internal optimisation to BCMath / Number - in 
some way memoize both the quotient and the remainder when either div or mod is 
called, and then document for users that calling one after the other will be 
extremely cheap to run.

But maybe that brings up too many questions about memory usage - e.g. is the 
memory for this reserved in advance for each instance of Number, or allocated 
when one of these functions is called, and should it be freed even while the 
object remains in scope to avoid using lots of memory if many numbers are 
divided or modded.

Reply via email to