On Mon, 8 Apr 2024 at 14:33, Barney Laurance <bar...@redmagic.org.uk> wrote:
> 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 * 10^exponent. > > 64 bits for the exponent seems excessive, and it might be nice to have > more for the coefficient but maybe that doesn't matter too much. > I was thinking of no exponents, just a straightforward integer representation for the fractional part, 14 digits long (48 bits). Taking two 64-bit numbers and combining them into a single 128-bit value would give us a range of "-604,462,909,807,314,587,353,088" to "604,462,909,807,314,587,353,087" for the integer part (80 bits) and "281,474,976,710,655" for the unsigned integer for fractions (48 bits). With this, we can achieve 14 digits of precision without any problem. I would say these numbers are sufficiently large to realistically cover most scenarios that the vast majority of us, PHP developers, will ever encounter. For everything else, extensions that handle arbitrary numbers exist. :) The ini setting I was considering would function similarly to what it does for floats right now - I assume it changes the exponent, thereby increasing their precision but reducing the integer range they can cover. The same adjustment could be applied to decimals if people really need to tweak those ini settings (I've never seen anyone change that from the default in 20 years, but hey, I'm sure someone out there does and needs it). - Arvīds Godjuks +371 26 851 664 arvids.godj...@gmail.com Telegram: @psihius https://t.me/psihius