Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121997 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73896 invoked from network); 13 Dec 2023 00:29:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Dec 2023 00:29:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3368A180057 for ; Tue, 12 Dec 2023 16:29:53 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 ; Tue, 12 Dec 2023 16:29:52 -0800 (PST) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-28abda2fc0bso1301088a91.1 for ; Tue, 12 Dec 2023 16:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702427375; x=1703032175; 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=YDvXGZDIRgrAj79t+xBRmeQSmuyJaWGmtpl8SBBe2IA=; b=dZSI5lxI2bRPDM1km+8onVUZxqyksApw2aSJt2yOm61fg/Amy38cQvePCHvTM6sjdw F0j5Rpy/ivrIPSfUVJ5DWjuKjWuhC7gANMFVu2EWTu8dW67/OsbpTq42gVs2ESitFDT5 6wc31tWIDJ2Zn6DbnZYWKw4yY51SPTaY6hU5viXO0gsyGX0g49POFY7BpSQX1/JS5OJE 9AoagwNM9hX0p7/1B0UmuaFGGFqlPDzs3mUHsO6MM0XUCpNKfq7mw8XE+5J1YIQfm7Oi wwhpn/TUqA4cs4cHU8uusdQEguXo3ASPpMSKMOIbHaOgL0duLWv47PNdxLs4iSblrFET Obhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702427375; x=1703032175; 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=YDvXGZDIRgrAj79t+xBRmeQSmuyJaWGmtpl8SBBe2IA=; b=gWDW46gKzI2HIQZaNyhYs1aKRrT0UhjUmLHS/eIlgHPETLw56Xxi9+fwDag+OPHsmW rf56x+rAvnpZB0BYys++jHpVWJqIybXK/7wbbQmWiT3lDSBXA2tFjcdqcXTiwwJnlJWD 0QT6Fify/gZig+69L/OE8DtkKabfZKdQn6V873xmdMBKXyT+2TSbpHXpb0pMK1Pex+co +9WNPC78ojrv+HiJFmr4scshpXKQjBDIhpnIoculI0HpQa5NgK8Z69rrOkQZHdUu8g2s vasBw/P3lvUQ4EIcZxK6PRu8uMeHAmG26o/Q7MwEmSnVJDh/UzF7tqSkeQDZAZLo/DpG WlWA== X-Gm-Message-State: AOJu0YzImjd/qPcfo2QNCs6ZNohAIeAzr5NpA3pDAd6f8yitmmmq4oSi lvDzpzCFfKK5xDlRqf3/NZQ+hUUU0OWHAA6Qazg= X-Google-Smtp-Source: AGHT+IFvv4ljJtPnc2c3/lAokzn9X/YIXcFXlEOLLqDu37LXiht2jAwkZq7p2dsXvvpPmUB01x63DkBXrgj0LM3B9O0= X-Received: by 2002:a17:90a:de01:b0:286:c00f:b622 with SMTP id m1-20020a17090ade0100b00286c00fb622mr5296746pjv.41.1702427374850; Tue, 12 Dec 2023 16:29:34 -0800 (PST) MIME-Version: 1.0 References: <18c42fdbb30.2831.17a3710df6d58f02ca570cc47e197a63@interi.co> In-Reply-To: Date: Tue, 12 Dec 2023 16:29:22 -0800 Message-ID: To: Erick de Azevedo Lima Cc: php internals Content-Type: multipart/alternative; boundary="000000000000ef17cd060c594295" Subject: Re: [PHP-DEV] Proposal: Arbitrary precision native scalar type From: jordan.ledoux@gmail.com (Jordan LeDoux) --000000000000ef17cd060c594295 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 12, 2023 at 3:05=E2=80=AFPM Erick de Azevedo Lima < ericklima.comp@gmail.com> wrote: > Oh, I just realized that I used the wrong word, so let me rephrase that: > > What's the name of the library you're talking about? Maybe the *pros* of = a > core implementation can be highlighted if we can see the limitations of a > user-land approach. > > Best, > Erick > > My library is Fermat: https://github.com/JordanRL/Fermat Mine is the ONLY one that I'm aware of that even attempts to support complex mathematical operations in PHP. However, there are other arbitrary precision math libraries that are more limited in scope. Other similar math libraries: markrogoyski/math-php: The closest in terms of features compared to Fermat brick/math: The most widely installed PHP math library on Packagist (due to being a dependency of several other widely used packages). Has extremely limited features for complex arbitrary precision functions. MPDecimal (the underlying C library that we have discussed using here) has extensions and functions for things like sine and cosine. Even just exposing those would make writing algorithms for things like 3i^(2+5i) much, much faster. The problem is that there's no point in using arbitrary precision numbers unless you're using the spaces after the decimal. I think we can all agree on that. No matter how good the implementation, floats are always going to be faster if you're unconcerned about rounding errors and such. So if you're writing an arbitrary precision library and you want to support the next obvious operation beyond add, subtract, multiply, and divide, you probably naturally choose exponents. Except, calculating A^B where both A and B have *arbitrary precision* and where the result will also have *arbitrary precision* means that you cannot rely on things like the `pow()` function. So you have to implement your own. Except implementing decimal exponents means you *really* need to implement `exp()` first, since all of the efficient algorithms rely on transforming A^B into C*e^D. Except the most efficient ways of doing *that* really work best if you have access to trig functions. And *ALL* your calculations in the middle can't be losing precision, otherwise there's no point in doing your own implementation, so that means all of these functions need to have implementations as well. This rabbit hole is *so* insidious that the BCMath library simple says "fuck it" and limits you to only using integers for your exponents. That's basically pointless though if the reason you need arbitrary precision numbers is something like a statistics application for instance, which PHP *also* lacks support for since the one extension that used to provide statistics functions is no longer maintained and hasn't been updated since I think 7.4. If we get scalar decimals that only support add, subtract, multiply, and divide, that's a huge improvement. But if we can take this opportunity to tackle *at least* the trig functions as well, that will enable a LOT of new userland code that is very messy and very slow right now. Jordan --000000000000ef17cd060c594295--