Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124282 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 DCA6A1A009C for ; Mon, 8 Jul 2024 09:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720431488; bh=su0iyWkpbzRb+vI0p4/d6ogh4c81V5RvCR6rritHuR0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=A83Gtz5dWs6S9flV8v238NVmLp1MX6oxfnc47woonYVDWpinekMmImJZ1NO7YYarG ihBfEc0DEfEyK+gGfd5WJSSZyQJ2nnkn2JUOkhTf5p5LWlTnsmxbP/NFIJADq29pSh TXUEvftWlcMPyJDmjf5pDoO4aAwI3dc7R4TGuZ4QVwGnr7Hi7N7qkxQGztD+WlMhr6 jQqJVsQYOZuPyHVn+K3Mhmzn4CEXl/JwuLzjDkdMnCwMnCGjr3vn5jUC/nTPxW+ELQ dIxZh2+/w41PhLAXzWXAIacsukToicem38D0GbgSR7KfCAegyPAsZh1jKhq0rnj0ca FRmfYFBBK0uvg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C0379180076 for ; Mon, 8 Jul 2024 09:38:07 +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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 Jul 2024 09:38:07 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-656d8b346d2so1832869a12.2 for ; Mon, 08 Jul 2024 02:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720431402; x=1721036202; 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=su0iyWkpbzRb+vI0p4/d6ogh4c81V5RvCR6rritHuR0=; b=ESfo3gcAtavpdYWTKKRctm0goK+6ZSUc8mvTeEi5Ti8AIcDcEifnx/nZ0n9LoH63tq 3PmAANZzosTEh+NdDNYn4ejBw8OEDfF+ZKcpUQg4Swwa46cFGrcSnRNUjFa0dAZYoaIC RcbjqhgEyIpv7Juq66JYiVRvH6GYf8TasdY0hnUO+HODdu2aJa69ABe8y+tBXzTquAmY WEEvqRl9yvnPcKvOe1sqWbe0g1YgeQBefQboYwictYFPoORKl3MEAp1rf69u/qN3AIIt 7TAO0ab+kCot5tHdtk1wT9XXf/iMyYUrvmOovIurst5KxgJpkCWZGrfmdgN+L3LVobZc sLCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720431402; x=1721036202; 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=su0iyWkpbzRb+vI0p4/d6ogh4c81V5RvCR6rritHuR0=; b=DwbdqQRd4JBqhIrUGvF2N5ugz3y+hWPocix1ecHHzp3Gm9Gb9fDl6Fw1zj3Pau4uQg v/QWx+PevBg7CcLSLPZrbptOkM3lheRaVhGaTq1N+R7PhzqoJksWRashbkAN6PujurLQ sZAC1BXe4Py0TlFTsqS14UPdzf2wzFH/fjZ+YLqVoayszTIKaoqUS1oTNX8wjxELDAC2 tGBKpJUiyq8pLqjLbeoDE9LFxdCmfRitnjswDYC70zjVi9L1LJBxel8dDTPMm8kQmj6t /hetb9pyImnFDZRFKIU2KDvX4wFhpuNP09XOQ5B5d6b9rU3daSGLmlZzRKM4TOCKgmg6 tgiA== X-Forwarded-Encrypted: i=1; AJvYcCWgj3BJnfminvOHx5DCnuCbiEx57XE2K3g2OJDAHAYBXSNm4gX8FPILWaxA2BvopdpadqJfxz4HmqMYzlaYaO5op2CTsaZFMw== X-Gm-Message-State: AOJu0Yx8sdo1gVE5KXEjMjdIOq7LncTNNkq4qTB0huOBe7RmStgnw0pZ xrVeErlHlN64Vhkw+Im6JgpBNe66UN0EHXkRkaKlvIlKSUXb9FZZxIDnTIzSQiGUFxcOOOKHv4I vCbGOEsrebnOgXRhiD36Tq4Tx69mkzEPA X-Google-Smtp-Source: AGHT+IHDxDToD6bHotuKsWJODyoRDxjHtDpEn386+JWa0JHODIogy+1PsgGwh4KGnkGA6PZJDrdxP/IVyPa4RMtuUUw= X-Received: by 2002:a05:6a20:72a7:b0:1c0:e322:e8c5 with SMTP id adf61e73a8af0-1c0e322ebbemr5123339637.26.1720431401446; Mon, 08 Jul 2024 02:36:41 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <668B4C78.2000808@adviesenzo.nl> <8FA0DE3B-2AF4-4110-9836-14E035DC8169@sakiot.com> In-Reply-To: <8FA0DE3B-2AF4-4110-9836-14E035DC8169@sakiot.com> Date: Mon, 8 Jul 2024 02:36:28 -0700 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Allow int type argument to BCMath function To: Saki Takamachi Cc: Juliette Reinders Folmer , internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000008b3796061cb926e8" From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000008b3796061cb926e8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Jul 7, 2024 at 8:19=E2=80=AFPM Saki Takamachi wro= te: > Hi Juliette, > > > Hi Saki, > > > > Just wondering: why `int|string` instead of `float|string` ? > > In my experience, floats are the more pertinent type for which to use > the BCMath extension. > > > > Smile, > > Juliette > > Since floating point numbers always contain a certain amount of error, I > believe that they are not suitable as arguments for BCMath. > > For example, 0.285 becomes 0.284999... in floating point. From the > perspective of arbitrary precision math, there is no universally agreeabl= e > way to properly handle values like this: there will always be people who > want to treat it as 0.285, and people who want to treat it as 0.284999...= . > > Therefore, I believe BCMath should not accept floats as arguments. > > Regards, > > Saki I suspected the same thing when I was doing my arbitrary precision library, but I actually have yet to find a test case in all my unit tests where this happens when converting to a string. You can see this here: https://3v4l.org/Ud8Cn Jordan --0000000000008b3796061cb926e8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Sun, Jul 7, 2024 at 8:19=E2=80=AFP= M Saki Takamachi <saki@sakiot.com= > wrote:
Hi J= uliette,

> Hi Saki,
>
> Just wondering: why `int|string` instead of `float|string` ?
> In my experience, floats are the more pertinent type for which to use = the BCMath extension.
>
> Smile,
> Juliette

Since floating point numbers always contain a certain amount of error, I be= lieve that they are not suitable as arguments for BCMath.

For example, 0.285 becomes 0.284999... in floating point. From the perspect= ive of arbitrary precision math, there is no universally agreeable way to p= roperly handle values like this: there will always be people who want to tr= eat it as 0.285, and people who want to treat it as 0.284999....

Therefore, I believe BCMath should not accept floats as arguments.

Regards,

Saki

I suspected the same thing when I was = doing my arbitrary precision library, but I actually have yet to find a tes= t case in all my unit tests where this happens when converting to a string.= You can see this here:

https://3= v4l.org/Ud8Cn

Jordan
--0000000000008b3796061cb926e8--