Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:128309
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 4F4A41A00BC
for ; Tue, 29 Jul 2025 20:09:24 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
t=1753819661; bh=Y6IpgAfKN/d1x71+gDYGV5ZBCoygHRmzo7qA1fa+XyE=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=dY3Z++mbd39773Sfui5UNzPzYFKQw8ycF5ogihEAPir+3eRYP+aA7CPBEx4z+St9p
GvCTarMNgdLMTkeEGWSfOY8ezjLM82cuXEAXIhUdr41wOLsG2sNRtc/WMLARyqhKuT
CTt33yWYqg87QkCLOzAUaETKS2DW9EJGqVmkhJ+eyo/Jy337+WsFyvpp7Xfupg8HFR
0OMjGhxA+5G2sb+hsH6Qypkq6148ArxJQsdDDC3nNNXySsd4rWXHpeCH4Hkhen7qb/
IRHEQsqV6EwKIKAR64AcuFvyOAvgAfYWL2Min/GOY0ezgfC2Ck+fF2pkUkWUG6Jyse
wiN0cc4nU6Gkg==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
by php-smtp4.php.net (Postfix) with ESMTP id 4B9531804AC
for ; Tue, 29 Jul 2025 20:07:40 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,
DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE,
RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no
autolearn_force=no version=4.0.1
X-Spam-Virus: Error (Cannot connect to unix socket
'/var/run/clamav/clamd.ctl': connect: Connection refused)
X-Envelope-From:
Received: from fout-b2-smtp.messagingengine.com (fout-b2-smtp.messagingengine.com [202.12.124.145])
(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, 29 Jul 2025 20:07:40 +0000 (UTC)
Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45])
by mailfout.stl.internal (Postfix) with ESMTP id 41A5A1D007E0
for ; Tue, 29 Jul 2025 16:09:22 -0400 (EDT)
Received: from phl-mailfrontend-02 ([10.202.2.163])
by phl-compute-05.internal (MEProxy); Tue, 29 Jul 2025 16:09:22 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc
:content-type:content-type:date:date:from:from:in-reply-to
:in-reply-to:message-id:mime-version:references:reply-to:subject
:subject:to:to; s=fm3; t=1753819762; x=1753906162; bh=edfOOfSiA3
OP6pvhwFwGGExWEQOTSC0EM9OXvXMCfAw=; b=GoYxp3oQ6F3M2xZQ9NnhmEuQ7a
UZFdLy+eJGFv/WQbtNYW+3YC19CyK8gOO0m0ZUdzIfmYMsRDE2knlyEQFPbCinz0
YKs1Ow5cKkIRW4BpqHUQoo3Jz10BTkTqqEkK7Qwdvx9IV52ScfyILcG8wGm1om7C
O8Ols2cq511ycPIn3ndchoUK7G6sz8HMGOMfpvjphS636vOSpc2Yiqig7nErUfC3
lK9zsX+DnNTwuKi6U1T2VAApyyyNv+6Fr6V2SX3vyEeLcPMOUZFeJL7svUDLSfaM
ga7rO7XU3vyq/CZ76HR2SErPtG/rTgPDbrBKwPCN0qN15kly0/LdUrbb5z0w==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-type:content-type:date:date
:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:subject:subject:to
:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=
1753819762; x=1753906162; bh=edfOOfSiA3OP6pvhwFwGGExWEQOTSC0EM9O
XvXMCfAw=; b=Xh7ycrh7rRZfWk/9WrJiXNf30qmxxbcEnlmAX6Px38B6P2gw2RX
31BhqhHu0fBFe5ujLs9qHmu+y2J9Od4ndK4Jw+PTcCyY+3AU/jyHkToYhwd4WxBQ
zegoOz0tR9PMFadokPRm+abBXVTClQ0/+oeqcuFxDNPCEe130n5AS+bbXg3YF4g7
4uh/HjvLVkHXdlK/Dok+6bpeq8Oxtt0XmIPu20i9KEIqIqM9iW7TgL5oJxQ+HmMw
YAmtz2BM5WPKN9+vjPQzWdP/8rrbMnHSO7xusEXeJxP3H8F1dAUFaL07OednZMXT
B4rACzDj4KKvCS4JFZOK6wdbyBupx70eGwA==
X-ME-Sender:
X-ME-Received:
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdelheeljecutefuodetggdotefrod
ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr
ihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvd
ejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhm
shhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeeggffhvd
egfeeuffetkeekleefuddvgeejteduveevteegvdefjeelfeegtdekveenucffohhmrghi
nhepphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih
hlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthht
ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh
hishhtshdrphhhphdrnhgvth
X-ME-Proxy:
Feedback-ID: id5114917:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA for
; Tue, 29 Jul 2025 16:09:21 -0400 (EDT)
Content-Type: multipart/alternative;
boundary="------------eVK9Hhv74yipiBPdelLBMb6x"
Message-ID: <639dcf61-1b15-4381-aaff-54f0bd6bc23a@rwec.co.uk>
Date: Tue, 29 Jul 2025 21:09:20 +0100
Precedence: bulk
list-help:
list-post:
List-Id: internals.lists.php.net
x-ms-reactions: disallow
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PHP-DEV] [RFC] Add "is_representable_as_float()" and
"is_representable_as_int()" functions
Content-Language: en-GB
To: internals@lists.php.net
References:
In-Reply-To:
From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]")
This is a multi-part message in MIME format.
--------------eVK9Hhv74yipiBPdelLBMb6x
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
On 29/07/2025 13:52, Alexandre Daubois wrote:
> https://wiki.php.net/rfc/is-representable-as-float-int
In general, I think the proposed semantics make sense. I'm not sure
about the names, but it's hard to think of a name that accurately
describes what they do.
> The value is a float that is not NaN or infinity
It feels a bit odd to have a value where is_float($v) would be true, but
is_representable_as_float($v) would be false. I'd be interested to
understand the thinking behind this case.
> Because of this, the function return value is also platform-dependent:
>
> is_representable_as_float(PHP_INT_MAX); // true on 64-bit platforms, false on 32-bit platforms
This is, at best, misleading: it's not the function that's behaving
differently, it's just being given different input. By that reasoning,
strlen() is platform-dependent, because strlen(PHP_OS_FAMILY) returns 5
on Linux but 7 on Windows.
As written, it's also the wrong way around: on a 32-bit platform, you
are passing 2147483647, which is a "safe" value; on a 64-bit platform,
you are passing 9223372036854775807, which is an odd number outside the
"safe" range.
is_representable_as_float(2147483647) === true on any platform
is_representable_as_float(9223372036854775807) === false on a 64-bit build
Confusingly, passing that absolute value on a 32-bit system will appear
to return true, but that's because the loss of precision *has already
happened* in the compiler: 9223372036854775807 will actually be compiled
as 9223372036854775808.0, the nearest representable float. So again,
it's actually running the same function with different input, not
different behaviour inside the function.
I suggest removing that sentence and example completely. There is
nothing the function can or should do differently on different platforms.
> Here also, the function return value is platform-dependent:
>
> is_representable_as_int(2**31); // true on 64-bit platforms, false on 32-bit platforms
This one is fair enough, but I'd suggest tweaking the example slightly
to avoid the same problem with different inputs: on a 64-bit build,
2**31 already is an integer, so it's trivially true. So either force a
floating point input:
is_representable_as_int(2.0**31); // true on 64-bit platforms, false on
32-bit platforms
or, perhaps clearer, use an out-of-range string input:
is_representable_as_int('2147483648'); // true on 64-bit platforms,
false on 32-bit platforms
Regards,
--
Rowan Tommins
[IMSoP]
--------------eVK9Hhv74yipiBPdelLBMb6x
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
On 29/07/2025 13:52, Alexandre Daubois
wrote:
https://wiki.php.net/rfc/is-representable-as-float-int
In general, I think the proposed semantics make sense. I'm not
sure about the names, but it's hard to think of a name that
accurately describes what they do.
The value is a float that is not NaN or
infinity
It feels a bit odd to have a value where is_float($v) would be
true, but is_representable_as_float($v) would be false. I'd be
interested to understand the thinking behind this case.
Because of this, the function return value is
also platform-dependent:
is_representable_as_float(PHP_INT_MAX); // true on 64-bit platforms, false on 32-bit platforms
This is, at best, misleading: it's not the function that's
behaving differently, it's just being given different input. By
that reasoning, strlen() is platform-dependent, because
strlen(PHP_OS_FAMILY) returns 5 on Linux but 7 on Windows.
As written, it's also the wrong way around: on
a 32-bit platform, you are passing 2147483647,
which is a "safe" value; on a 64-bit platform, you are
passing 9223372036854775807, which is an odd
number outside the "safe" range.
is_representable_as_float(2147483647) ===
true on any platform
is_representable_as_float(9223372036854775807)
=== false on a 64-bit build
Confusingly, passing that absolute value on
a 32-bit system will appear to return true, but that's because
the loss of precision *has already happened* in the
compiler: 9223372036854775807 will
actually be compiled as 9223372036854775808.0,
the nearest representable float. So again, it's actually running
the same function with different input, not different behaviour
inside the function.
I suggest removing that sentence and example completely. There is
nothing the function can or should do differently on different
platforms.
Here also, the function return value is platform-dependent:
is_representable_as_int(2**31); // true on 64-bit platforms, false on 32-bit platforms
This one is fair enough, but I'd suggest tweaking the example
slightly to avoid the same problem with different inputs: on a
64-bit build, 2**31 already is an integer, so it's trivially true.
So either force a floating point input:
is_representable_as_int(2.0**31); // true on 64-bit platforms,
false on 32-bit platforms
or, perhaps clearer, use an out-of-range string input:
is_representable_as_int('2147483648'); //
true on 64-bit platforms, false on 32-bit platforms
Regards,
--
Rowan Tommins
[IMSoP]
--------------eVK9Hhv74yipiBPdelLBMb6x--