Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121998 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75331 invoked from network); 13 Dec 2023 00:33:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Dec 2023 00:33:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E0FDE180053 for ; Tue, 12 Dec 2023 16:33:35 -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-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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:33:35 -0800 (PST) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-28694702c18so6200827a91.3 for ; Tue, 12 Dec 2023 16:33:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702427598; x=1703032398; 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=i5ulHcGaSOd2s8C4duUVnKFzzhfdoMybZpu03zbxT7Q=; b=kBTyvjZ+8xf1QlqWbGUK6EXGp2IugCAqux4pEGNUyFk7CeQStErK3O2LJHLm7M2QDm QVXBL8U63UdcAu3/OuoRg5KvNSM3ICxLyCBoP/sgsO0HReFCcH1zN1wpn28ZDUnFPdfu Y/QT7TfduSLaM35qVMh3IXmod6JdI0auFgUtkAbgNliJ8xhGjIgOwUH6zxffoqDjo+fa CGF0n2PFFRQMBRtoUFwwgMHUXSxgg/DK5QnXHZcTsqQk7QW1IaWXCPjP9LxxKMCkm+KH ZES/l3eA7bNfqu6bDiRbrudjx3Y6AeQXSiMXc67XRDdGGcg4ENabBOH0Da/7/m+0J+qB 2vLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702427598; x=1703032398; 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=i5ulHcGaSOd2s8C4duUVnKFzzhfdoMybZpu03zbxT7Q=; b=vFQw4E3PeGeJfuHG1uIgg1tsJ7TA1PIN88IsFmV9yilTcpqLR96zgZ3AtO4xztBBZk noEemPwFhKT6FdlTKrT5Sjy6J+0KmdI/vl3I7JDoW1b7UP4rpL5j3R2oONAaxqvmau88 kP6hN/XmXUOOdWo6gjbax1LvapSruDtkajG0wwacnvvIjynFy90Y3Rw/EdLx+f7hmjJ/ AdEi5PemZbWP4T3X+UFV9Xd7DeyOOHEJHTNAOaehnW8TTvGkDslmyqDx6R2CizM/F7PF iUHMXXjn9VoQV2Gze+warCK82NIWjBZ3XTsT4kD62NwgBX/97494hPsUGEY/LNuGmZLG AIBg== X-Gm-Message-State: AOJu0Yw7itVeMhdHo5jLSfAAme1f72bbxRziQC2Z/ehAdXxy9XxRwCsh sxygv0f84HnLX3zDKZ079ArVdgo2eMgAAnXyKd/hOzs7 X-Google-Smtp-Source: AGHT+IGc5ELxS4vqcVNWZebXUYD1HSJU/ecrBS9zRZdUNzF0y6x80EFAFYNdwjmw1IoiV5+yqXoUDLTloLpwLvTgdcw= X-Received: by 2002:a17:90a:cb0b:b0:28a:c002:7358 with SMTP id z11-20020a17090acb0b00b0028ac0027358mr1648684pjt.71.1702427597858; Tue, 12 Dec 2023 16:33:17 -0800 (PST) MIME-Version: 1.0 References: <18c42fdbb30.2831.17a3710df6d58f02ca570cc47e197a63@interi.co> In-Reply-To: Date: Tue, 12 Dec 2023 16:33:06 -0800 Message-ID: To: Erick de Azevedo Lima Cc: php internals Content-Type: multipart/alternative; boundary="00000000000039eb7f060c59508f" Subject: Re: [PHP-DEV] Proposal: Arbitrary precision native scalar type From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000039eb7f060c59508f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 12, 2023 at 4:29=E2=80=AFPM Jordan LeDoux wrote: > > > 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 arbitrar= y > precision math libraries that are more limited in scope. > > Other similar math libraries: > > markrogoyski/math-php: The closest in terms of features compared to Ferma= t > brick/math: The most widely installed PHP math library on Packagist (due > to being a dependency of several other widely used packages). Has extreme= ly > limited features for complex arbitrary precision functions. > > MPDecimal (the underlying C library that we have discussed using here) ha= s > 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 agre= e > on that. No matter how good the implementation, floats are always going t= o > 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 int= o > 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 you= r > 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 PH= P > *also* lacks support for since the one extension that used to provide > statistics functions is no longer maintained and hasn't been updated sinc= e > 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 n= ew > userland code that is very messy and very slow right now. > > Jordan > Apologies, I just realized that you were asking about the libraries that implemented rationals with complex operations. I don't have THOSE libraries handy unfortunately. Even my library converts to decimal first. Jordan --00000000000039eb7f060c59508f--