Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128559 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 lists.php.net (Postfix) with ESMTPS id 37BD31A00BC for ; Tue, 26 Aug 2025 14:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756218530; bh=KPffkRUHGIUfuf2kLyIP163ZGUt0dsBbMJYnxCSbzZE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=klFu8Mu+pqYJwrDVhLifJvsIhFAs21LVKeqWXeQn1DtdgTUNNGaa094oiCeXIggN+ EpKSblBdEtFbaP//A4cIif27X4gsaGex7X9XKQVVGD12uo6HkBRPGs2h4+54V2Hcwq FOIk0is0HZORgAwAnLYsYLbIxp0ZBwJxFbVlyS1K3nPAxYqNsMoKVSJOgdTKdJj6im tdgf+0b99lAAxc6x4/hp0sJvUsaPxgtNbE6q1e+zH1XhX4La6Y9KPlL97D/Jt2Z5SL cQsOgtZDVo734AcvJhEy12LjYhO+uFzvd/8pnF9bnI7GBh2zjUYFN8/1OWbHfxLOwf A0s0sjuXBhZMw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 432DE180077 for ; Tue, 26 Aug 2025 14:28:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,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.1 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, 26 Aug 2025 14:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1756218620; bh=HNdnW7A2xBjyNP+0BgbIsqCkNoi9REfp+sdGFGjPRM8=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=HtJBRiOoCwO2aUDCtUUcpCKA9GROgTOBlPUwpgJemYjPUimHLJ+kZK+jOOTylxRv1 TC5D9W54/p+agqRfOZGTF3IfqEXkqivLygoptL2d4Ix09l0DNzIfcd6ZK1o0tPCfj1 jz0aEqoqQXkXOrhyzoA1LkyVJx3TdMMXqgkfW8cSLJuKwDNXt/VDyHrxagHxZNfZWj YNY6oG6eKwhyaLkkGmiNdloUC5pe9xDp5dW5N7rUHIlTv22kD77+rR7TOSQv6wer3y DrGgzxTqHsa6Z78CcDZA8kj8klTHrdfyCZu1cKE0JYkRj7ardoOxRckbl7JVtTKKwe S3NdwTT34QNJw== Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Tue, 26 Aug 2025 16:30:19 +0200 To: Alexandre Daubois Cc: PHP internals list Subject: Re: [PHP-DEV] [RFC] Add "is_representable_as_float()" and "is_representable_as_int()" functions In-Reply-To: References: Message-ID: 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 Am 2025-07-29 14:52, schrieb Alexandre Daubois: > I would like to present the RFC to add the > "is_representable_as_float()" and "is_representable_as_int()" > functions. These functions provide developers with a way to check > whether values can be losslessly converted between integer and > floating-point representations. > > https://wiki.php.net/rfc/is-representable-as-float-int Thank you for the RFC. I fundamentally disagree with that there is a single, obvious and meaningful definition for `is_representable_as_float()`. In fact right from the beginning of the “Proposal” section: > The value is a string that represents a valid floating-point number > (e.g., “3.14”, “1e10”, “-0.001”) 3.14 is not exactly representable as a IEEE-754 double-precision floating point number. The two nearest representable values are 3.14000000000000012434 (this one is the nearest) and 3.13999999999999968026. Returning `true` for `is_representable_as_float("3.14")` is therefore wrong to me. The introduction is also wrong. JSON does *not* specify that numbers must be representable as IEEE-754 double-precision floating point numbers. The grammar for “Numbers” is independent of any particular representation and transmitting numbers > 2^53 is perfectly fine if every system involved can deal with 64 bit integers. Also just casting a non-representable value to string will break any consumers that are strongly typed and expect a number rather than a string. So that doesn't make sense to me either. I also question how meaningful it is knowing that a given number is exactly representable as a float when (e.g. a power of two) when almost any operation on it will incur implicit rounding. For `is_representable_as_int()` finding a reasonable definition is much easier, but I don't think I've ever had a use case where I needed to know whether a non-integer value is exactly representable as an int. Long story short: What actual real-world problem does this RFC attempt to solve? The list in the “Introduction” section is not particularly meaningful with regard to the real world and the JSON example is wrong as outlined above. Best regards Tim Düsterhus