Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124314 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 7C0A51A00B7 for ; Tue, 9 Jul 2024 17:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720547365; bh=2+O16CU/Q6X5umlwUo+tN6R/Rl/HDcBDV2SDvRXLQTQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=aASdUbR1Bn20SnmTgwwJVx94LaAgJQH9VoT4jbeWSAo0o+nj1LzAnmPA/HopLZdSV yFDbsl7MvIHx9HbxS74XkzM0KwHzAtqQOTVgvMfQWxcwKC9ibxodE0kx2DzOOhLKEA 7Mj2suJcoL7LP397z3ayHvgx7/dEYR/BrGSXYZy1MOhHXeOCdBn27vJxRFd+leq1Jd d1alO8+EDYK2SVvnoVuc04OuDrQRw1Si35QdCRfbahLEA3RjIvU8DV53NKXRZ2YriU X7LPTAq+4MqkML8D6Z30sh2N6ykxgPdgI9GIu0zOsaHEy5srE4RFkeE7+LwDhJi1w4 pvnjaA1zA0NYA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F1D55181265 for ; Tue, 9 Jul 2024 17:49:24 +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,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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, 9 Jul 2024 17:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1720547277; bh=xxsutVB0DM2AauHc7fyOCG1gZ7HHvgvDNz7aYfxzcsU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=kE4fN+uuOzOEJwFTelaAV2WLKY7L/EvNF5aghWXaInJt4RJ2cTpA0ckscnHvOqVwx XlY6w/9Nl2XPChXsfTMxqNqc3OF2i4vbu5geCPJx5lKH8E/+5G6VSbzhL2e2Wdu8h4 bOHo/O5sqW+8zLbM1Axbch4al2/w5Iecc88S0UKU9H8N+W3PkxwLJBMGC4LLYgc+b5 0dHPPiBeA9VxXvRs91JskcTC+ZWAAyWbmcVc4IBqb5k0gK35i9J13b/Bg25oEyLVGI KWpBS+Kn9vp5WlSI9KxI7HArKlVWrhrxf+XzPu7qkSGbeTxKLUP22lP+h7PEUPwv0K Jxd9+LjudHitg== Message-ID: <2ac2914f-1672-4f7a-863b-86b6692bff60@bastelstu.be> Date: Tue, 9 Jul 2024 19:47:55 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] Allow int type argument to BCMath function To: Jordan LeDoux , Saki Takamachi Cc: Juliette Reinders Folmer , internals@lists.php.net References: <668B4C78.2000808@adviesenzo.nl> <8FA0DE3B-2AF4-4110-9836-14E035DC8169@sakiot.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 7/8/24 11:36, Jordan LeDoux wrote: > 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 PHP emits the shortest possible representation that roundtrips, so the precision loss indeed does not happen when converting from float, but rather when converting to float / when the implicit rounding happens during the calculation. Nevertheless the inherent rounding error of floats and an arbitrary precision maths library do not mix: Users should not be encouraged to mindlessly pass a float, but rather work with strings all the time or explicitly perform the necessary conversion as appropriate for their use case - which of course is easier with strict_types enabled because then the conversion would need to be made explicit with a cast. Best regards Tim Düsterhus