Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128251 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 DFABA1A00C8 for ; Mon, 28 Jul 2025 10:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753697812; bh=6mwnLt7XWKwNbC+02VtTuiBnqdY07SZqNu1uvKYE34I=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=kucWVyraHK0SlC/SKWFuoOU1iQFX1qbfla3JmHxqxKr46z18Db1wAIt4MHUtOBwz+ znzH4M//UeJYOoZglBi7zoiSaCRMK2d1aV7FHhiwBQ+A0YzPI2Y+8a9hPkCu+8tnAM tcRBOXwuY/x8X7sVB5B0BGdGLggC7I9xH92MiUkPhDlM491E8xQFzBW9Iyxg/Lunsd dklewxfGV6FSdqckBdHXxsCZz1z3Iw35aitdVW+3a7goYJPTHJrCVy2UsD5jtlyViE WUylAeGZHYX9TbXaMMoL1tayv8QnSo/TThhoYf2Zyv5oHLPuH/5+bdrJ6g9U1pqYMH 28XV5ChTQmBdg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D0A81804E5 for ; Mon, 28 Jul 2025 10:16:50 +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.2 required=5.0 tests=BAYES_40,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.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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, 28 Jul 2025 10:16:48 +0000 (UTC) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-ae0c571f137so808599966b.0 for ; Mon, 28 Jul 2025 03:18:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753697910; x=1754302710; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=ya170RNNSqLCQeiUFW4r+3nFeHWq1L5oj1OYg5gAkIY=; b=WpLPeNY+n0w4eHJjsjmZ9R3AvYQTx3o+WQzHxPEBC3f+aUMIgHCK0Hg3HWyHPxiq0Q Vg3n4OC7l10vqJ7aBVXJadjrBQrNzbtjqR5SepEeOwInjxYvXJ7/Mh+rFRn643u2MzeQ h02SDL3UoqdNVVMS4IK8zfnfD7DJAwfHeqxoh2KYCSCsvs1Vd5EQOibY/KSh7z+q4srE aMXcbg03M5LU23z1JgRNQT3KE2/0k9RGjlQpbCip6/QT7lZsX8XfKyxtwziRRy0xZh1y gXCGvw8lfPgHuRNoEJn6+sopDgfhIFMEF9ViR9z1X1uzXwxu//1FNEdI5FiMaXEOjmrs fUgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753697910; x=1754302710; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ya170RNNSqLCQeiUFW4r+3nFeHWq1L5oj1OYg5gAkIY=; b=LyvO9Fp69X6HECGYQSYg2ggsVUdT9zKa6gTUnzPTKkFP8g/q/lpsL/7IUV6Wwgfk2w auFw6rU71zf6p7LtuZMnWFb1W/6M9Fy69rGLkv2bQ3DllttEASXlb70fu2tsmIoa6vmn 9cqHcnO92fSYUcA9Erkd6PPk9NnLUjFspFkIaD2DSPtFN9Fgc0Gli41vCgKlB7WS1uUd a7ccjNnNvwgtdrMz6MbNn3b/AP9cTArii7ROlLcad0kiF//87Elbh47+T+HIAW8Y57Rf vPmXjg78fFL5KF+K8MaTr9A7YAyA+G7aDCbZI6/ASlOZqYr30ExIIa+aYcYaFy+eGd6V X6Bw== X-Forwarded-Encrypted: i=1; AJvYcCX3N2XxJaHWg/zsZ5mADyhlnYegdA4HMMwQIunRMdpHCa+ttagwGTp0c2g7kfL0Ku4igtr21EajQAg=@lists.php.net X-Gm-Message-State: AOJu0Yx3KointbmqnoMKTVC8S95NxnSU7G57cXI10uzP7Z8bpeMPw4S9 ivhPO3pqG7rgiCfEBJinY3bNXUC2csQIOJtD/8mbOP1Pysviy3vwAVg5 X-Gm-Gg: ASbGncvwoFf0gxAFNdeM3lqRToNMLuzZKusFaHmGS8vOpW+bj2pP4ztbfX2aw1c+uo+ BlvtWfvChPoxhEFCpwp6aQtnn3ykX76wk2BHkhEZ7pV21p12mIKSKrTS5FqKQHwYJRiBKRRJljr cBh7v92c6mEdNeqIHwfPjMD/PciI2PSvwpKrvq5pVJ0fmsz7V9LWFTS12pGP7eNmSa6bE+Pr2+9 fIIEIDFkymujW7O1OxN14kdDquO/RVbrEIe9XGnA198+rbRWJWN+/Z6P+6oTbHZEBbBQ/WmWPI+ Aubruub6Yj7ZaQ2kBJP4koPggOLrnO3quEDmEHN2dXNlZzXkP+HTwYnv8mDG9lvJBrpnZdkBeew 1ITtvA3ySYRMH62BNmboilgyj3uJGStRGw+bjScYD X-Google-Smtp-Source: AGHT+IHKfCcMcA03OAHGZLKOw99g2QObLCqa5M6idsuIfj6sM3WY6UPrKMZ4M/8r0B6eEhwhUhgxsg== X-Received: by 2002:a17:907:db16:b0:adb:469d:2246 with SMTP id a640c23a62f3a-af6175096cbmr1243401166b.17.1753697909665; Mon, 28 Jul 2025 03:18:29 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-af635b427aesm402826766b.145.2025.07.28.03.18.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jul 2025 03:18:29 -0700 (PDT) Message-ID: <20FC2F27-1EB0-4C33-A3DC-EDF7FF5961F3@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_678904AD-473E-4CE2-86FF-A67F313050FF" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] [DISCUSSION] Adding the "is_integer_safe()" function Date: Mon, 28 Jul 2025 12:18:18 +0200 In-Reply-To: Cc: "Rowan Tommins [IMSoP]" , internals@lists.php.net To: Alexandre Daubois References: X-Mailer: Apple Mail (2.3826.600.51.1.1) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_678904AD-473E-4CE2-86FF-A67F313050FF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 26 juil. 2025 =C3=A0 18:13, Alexandre Daubois = a =C3=A9crit : >=20 >>=20 >> I'm not sure if accepting floats in the same function makes sense. If = the question is "can this value safely be stored in a float?" and you = give it a float, then the answer is surely "yes". You have no way of = knowing if it _already_ lost precision during a previous operation. >>=20 >> Possibly there could be a separate function which asks "can this = float value be safely converted to an integer?", but that implies a = different definition - it wouldn't make much sense to answer "yes" for = 3.5, or NaN. >=20 > I think we can see this function more like "can this number be > compared safely?", e.g. `var_dump(2**53 =3D=3D=3D (2**53)+1);` returns = true > as these numbers are not in the safe interval. A name like > `is_safely_comparable()` would fit better maybe. This is not correct: 2**53 + 1 is perfectly =E2=80=9Csafe=E2=80=9D (for = 64-bit builds of PHP), see: https://3v4l.org/P939d The specific notion of =E2=80=9Csafe integer=E2=80=9D as introduced in = JavaScript makes sense only for numbers encoded using IEEE 754, which is = what PHP uses for `float`. In PHP, there is a specialised type for = integers, so that the need of such a function is not clear, because = every integer encoded as `int` is =E2=80=9Csafe=E2=80=9D. Or maybe you = want something like `is_safe_integer_when_interpreted_as_float()`? Also, note that the particular Symfony example given at the beginning of = this thread uses a function that expects a string, not an int or a = float. In that example, something like = `is_numeric_value_producing_exact_integer_when_interpreted_as_float()` = could have been useful, but this use case is very specialised. =E2=80=94Claude --Apple-Mail=_678904AD-473E-4CE2-86FF-A67F313050FF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8


Le 26 juil. 2025 =C3=A0 18:13, Alexandre Daubois = <alex.daubois+php@gmail.com> a =C3=A9crit :


I'm not sure if accepting floats in = the same function makes sense. If the question is "can this value safely = be stored in a float?" and you give it a float, then the answer is = surely "yes". You have no way of knowing if it _already_ lost precision = during a previous operation.

Possibly there could be a separate = function which asks "can this float value be safely converted to an = integer?", but that implies a different definition - it wouldn't make = much sense to answer "yes" for 3.5, or NaN.

I think we can see this function more like = "can this number be
compared safely?", e.g. `var_dump(2**53 =3D=3D=3D = (2**53)+1);` returns true
as = these numbers are not in the safe interval. A name like
`is_safely_comparable()` would fit better = maybe.

This is not correct: 2**53 + 1 = is perfectly =E2=80=9Csafe=E2=80=9D (for 64-bit builds of PHP), = see: https://3v4l.org/P939d

<= /div>
The specific notion of =E2=80=9Csafe integer=E2=80=9D as = introduced in JavaScript makes sense only for numbers encoded using IEEE = 754, which is what PHP uses for `float`. In PHP, there is a specialised = type for integers, so that the need of such a function is not clear, = because every integer encoded as `int` is =E2=80=9Csafe=E2=80=9D. Or = maybe you want something like = `is_safe_integer_when_interpreted_as_float()`?

Al= so, note that the particular Symfony example given at the beginning of = this thread uses a function that expects a string, not an int or a = float. In that example, something like = `is_numeric_value_producing_exact_integer_when_interpreted_as_float()` = could have been useful, but this use case is very = specialised.

=E2=80=94Claude

=
= --Apple-Mail=_678904AD-473E-4CE2-86FF-A67F313050FF--