Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123042 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 7CF371A009C for ; Mon, 8 Apr 2024 12:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712580203; bh=ZjDp24Scl94XQcAU87MNDaK2OdBblMjdXKRfPiA/Njc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LchMBG4p4OYUCWzTLX76dh7lwOnX/vBIu8Zo8wdTKtSVcrwB0Fdf98IgomeLvvTC2 D7YLCuHVaQpZn+jd8NRkELUg/yim+UsRymk/8SEmdplcaPiWK4xQa3gmjVgHfX+NGa TUXAJEPbh7sKyJ6bQ+kZ0I15yJo+0yVejKKHX/VSXtWNnlx3FaeKPSaEzJclPZxnCu awRbw8Jli+9nFoztSfkg7Dzjn46LehSRwy5Xaq5a8anVDWtMtF8G5ScBv5xt63qUtM +zhTJxe8SGrGJnFmgLQj7kO16owpqGVXzxF4Av2u4LaFvwVuVvRqQpXku4ujcZ9T2u C6vsI8roznd1g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 73EDF1807AB for ; Mon, 8 Apr 2024 12:43:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 8 Apr 2024 12:43:22 +0000 (UTC) Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-343e986aa6cso955453f8f.1 for ; Mon, 08 Apr 2024 05:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712580169; x=1713184969; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZjDp24Scl94XQcAU87MNDaK2OdBblMjdXKRfPiA/Njc=; b=GFa24pvRZMGy4akoU+EgcOI+zICXXzY3cwPaLGh4FUoTB8efQf8QyiDuzaZA6OdlaF eYekV3TUTZCcLOXTd4mteo/D7eal/L0WOySIY4NyLDhkjaJFXZ70CGXa1ax5Z476//qK UUzbGbem8uHDWik/AYIEFmMtFI2AWWXV1YhT+OnJpRI9+kbUL2PcqJmISp0gnCum5dSv Wiv8UxVJ0AicEjhnMUp1hLY73fo0wxU8OPlflm1FuiDFR9AWuM1KD0lz/z0ROVGQ/EvR ameeIMK9QUBtn1iRaVCuMOvdyGHGD2FMUADFArpdChdRoy6x+pLEiLPGXsjNkEXKQLdO Hpzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712580169; x=1713184969; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZjDp24Scl94XQcAU87MNDaK2OdBblMjdXKRfPiA/Njc=; b=e3wiz4U7Idf6Q1UilSmLDQN+GTAySl9wiUES8H45n16/YgpLLDUhxEPLxSzE4225A0 bpFkFtEAwEB5ydvSqoXmTMJ8FK6CbmMXV1qE01/iQelgTbGzvmrp0ySCZGrk+dcK8l8Y ygQ6sgkir46xi3b1KDf2+pbhOGakmgIRknvwNjDF7lCFsNWY+iPxH07iw4rlO5hzQmLy gcepml4fQdngxodo4DHAGAiupD2Zqmuzu4nvlKZ67SfTiVgCMj0qtq8w6noxEdRKxufG /MYRUnKk1dAjzSTXQHtOrfXwn1zQIsYpt1cXrd31Tx7mnS7c0tv6lCzOflgM0EIUsoUj EC0w== X-Gm-Message-State: AOJu0YzCveiZjYmtGh/tLJYHRY6Fc7ntKvsLP09tBiNouLapfnYI4AE1 uFWuUtIHSesjvh1xwOR2HUU9rZl6tirz38TThzVT8z76/qdIAdidYnj7ZAtgE1+1bxNUZDXsLPJ BAlmd7aFvVbheDmmIvwJRTILR/4h6MNY8 X-Google-Smtp-Source: AGHT+IHcA95wgaM8UJzDqzZl17mCMJAdzPJGi3t0IxB2grPvTWERCiodjjor9wb2YaxAWqAPAjY7rIKKu8v4iK0Luok= X-Received: by 2002:adf:ab01:0:b0:343:826a:7a36 with SMTP id q1-20020adfab01000000b00343826a7a36mr5773462wrc.58.1712580169082; Mon, 08 Apr 2024 05:42:49 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <40553F28-2EC2-475A-BD8E-1D6517AA2A51@rwec.co.uk> <2B518F62-B774-45C9-82A2-EF6653AAE34E@sakiot.com> <57c268e9be57edad86155c461b0fd181@gliadin.co.uk> In-Reply-To: <57c268e9be57edad86155c461b0fd181@gliadin.co.uk> Date: Mon, 8 Apr 2024 15:42:12 +0300 Message-ID: Subject: Re: [PHP-DEV] Native decimal scalar support and object types in BcMath - do we want both? To: Barney Laurance Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000a0b2cc0615952439" From: arvids.godjuks@gmail.com (Arvids Godjuks) --000000000000a0b2cc0615952439 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 8 Apr 2024 at 14:33, Barney Laurance 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 =3D 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=C4=ABds Godjuks +371 26 851 664 arvids.godjuks@gmail.com Telegram: @psihius https://t.me/psihius --000000000000a0b2cc0615952439 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, 8 Apr 2024 at 14:33, Barney Laura= nce <barney@= redmagic.org.uk> wrote:
On 2024-04-08 12:17, Arvids Godju= ks 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 =3D 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 exponent= s, just a straightforward integer representation for the fractional part, 1= 4 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 in= teger part (80 bits) and "281,474,976,710,655" for the unsigned i= nteger for fractions (48 bits). With this, we can achieve 14 digits of prec= ision without any problem. I would say these numbers are sufficiently large= to realistically cover most scenarios that the vast majority of us, PHP de= velopers, 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 chang= es the exponent, thereby increasing their precision but reducing the intege= r 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 ou= t there does and needs it).

-

Arv=C4=ABds Godjuks
+371 26 851= 664
Telegram: @psihius=C2=A0https://t.me/psihius
--000000000000a0b2cc0615952439--