Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128241 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 BBF511A00BC for ; Sat, 26 Jul 2025 16:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753546332; bh=vtz+7ntPkHgaNXpBqgNw6BLFFx+wlBwjLeid/8MlCXA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EkCdTD65Rz7bvu0XayZQDuP2RRC/GtE38jPmVPgoaExDDs14yq8c3ARfPp8fV/TXZ 2EzSvHDfrLy75QWgH7BLxgERxyhDgMMmSoJQs6Xs+syJpdxM+qmxs+q0aMblH3mLCy I7M4qyBsqQZX0hHOY5a4hxXtcAwsKax8iqsQ9yCWOCCSfmzaZPn6/StYLDyWE5i3d2 kbkABs99Kyro88VruZ6qZRQNC3hWB6mJQ3nnSU6rE+PA/lht/nTM+NsMmLfggxfhCS yV2xsjGIIrfpypgm1NlkyB71iYIyMzv6z6xGRy6K44polrBQQwXkpQG8T8PKsV5PAc pyeEk5u+6vUuA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EF3D61801DA for ; Sat, 26 Jul 2025 16:12:11 +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=-1.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 ; Sat, 26 Jul 2025 16:12:11 +0000 (UTC) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-60c5b8ee2d9so6352270a12.2 for ; Sat, 26 Jul 2025 09:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753546434; x=1754151234; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vtz+7ntPkHgaNXpBqgNw6BLFFx+wlBwjLeid/8MlCXA=; b=jVFsNCEXTvOi2FaxDwto4Xxhu7reLnsm8MHqzwME/0bOwH+AkcoICNgA3/sr6btb7R DPIB4pTV5NfkIhh/OJLwdWbCWNXCn8U1M/FmNwfqVD7sQjEc3YfFgRi5gTE3g/eYQxra osYuYaRwYHaLTqZpnBAGzjT6RZZ58CdLMoUu9i3IRAxHvFbo8wkLCs7flLjdGqFPycvP g8MFEbP1wXnQ7FqEMd9Gd1F6PuqBLDfqRUy36iq+e3UC9eaxtO4aFOb75qdpco7RAPox 5E5HpCXMJKwEzk2NO2ecBWr+wjSz0SvOzyrNCuIHxuHqMAFyw2MH9Xme7l7jWuNYxdBh QbFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753546434; x=1754151234; h=content-transfer-encoding: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=vtz+7ntPkHgaNXpBqgNw6BLFFx+wlBwjLeid/8MlCXA=; b=pQgXoXVAdwP6ZUaq4/w4x/KhnHeoUoXOFd6g3+q1oXBf61/05x6mVWLcXh2vfFGuNv 9n16Z0KM5lnwEsQScs6KzuRF6/YOxOYgJgJACL8NkIb3FfUiXzq356YK9JuzG5h/1L3u N46VEZGEip2Qi/7JTlyl4EBfVVlQ9Nr2A80l6OVNthd5Kkt2CJcHYXsi248WHwtdzoIp xtDlF//xD3mANPCg3Xcp6ur5DJzgaQ5qy2a7LSsLMoKuBPSPzzfhf4U5+CtdHIM4rRs3 55DULntvnq8ODzTQmDTnRUrRn1AM4MZMliTV5Guu3FQosB/EGrej9ji5v+q7JMU+P4gK SD1Q== X-Gm-Message-State: AOJu0YxIijwbTlo7eE0CaqeNTPR/WtN3aSrESJdDjQfxyo+MYVGY79Ra olDMnf/TDI6DVJ9uaQde2xDQ1WYKu09qO4OxllIjrdfmJkWebHYM2+Ks7T67x574vX+OddHezZk g+f9ZF8xwieUwx2/vj11Sfp2dM0lCcVxkcg== X-Gm-Gg: ASbGnctAkKm8CucpP0covzP4/51oyjd5iJHye9VtXj7LfvYjZGv0j8f+HhHyt5Tjnh7 6tUs8xDQd9CtJEFDFkqrLxwk30jOI96rN0u3V31wchP7eUR30nVDL381UkioGUgvebYHfc1VJ0+ AxPkG1/pJjRb8LCw/ZakNyvYOTzHCjx30wqw9/0qzbc+wlKcq48VbTdSacoYHb1ZgTI/I33Tmdi 30sUk8uHQ4JgZee0cTei8cugw8YTi0vmiiYgKV/ X-Google-Smtp-Source: AGHT+IF27vZOMqrI9WGa+CUUhd6cGEg2fg9eRaM2bEIavwDIDFebnE/ura19km2T1wr9piiyfJNxwfrghdwcTL9AtTg= X-Received: by 2002:a05:6402:278a:b0:602:17a1:c672 with SMTP id 4fb4d7f45d1cf-614f1b9b921mr6009937a12.8.1753546433990; Sat, 26 Jul 2025 09:13:53 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 26 Jul 2025 18:13:42 +0200 X-Gm-Features: Ac12FXxtOqpaDvPX0C37JklWVcS_0fXCU49dnkvtVVYCk5CC-IGQppyPPfNIYRA Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] Adding the "is_integer_safe()" function To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: alex.daubois+php@gmail.com (Alexandre Daubois) > That suggests maybe the name should communicate "safe for JavaScript"; or= more generally "safe for 64-bit IEEE floating point". > > is_safe_for_js() > is_safe_for_float() I'm not sure we should mention Javascript, because it's actually related to floating point storage. > 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 va= lue be safely converted to an integer?", but that implies a different defin= ition - 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. > My thinking is that this needs new syntax, to avoid dozens of specific fu= nctions. For instance, a generic (or generic-like) form: > > function can_lossless_cast(mixed $value): bool > > can_lossless_cast(2 ** 50) =3D=3D=3D true > can_lossless_cast(2 ** 54) =3D=3D=3D false > > can_lossless_cast(2 .0** 54) =3D=3D=3D true > can_lossless_cast(2.0 ** 65) =3D=3D=3D false > can_lossless_cast(3.5) =3D=3D=3D false > can_lossless_cast(NaN) =3D=3D=3D false > > can_lossless_cast('9007199254740991000') =3D=3D true // less than 2*= *64 > can_lossless_cast('9007199254740991000') =3D=3D false // more than= 2**53 > > can_lossless_cast('9007199254740991000') =3D=3D true > can_lossless_cast('3.5') =3D=3D true I really like the idea of generic functions, I however imagine it would bring a lot more complexity and really profound changes to the engine, well beyond the scope of the proposal. Maybe the better naming of the function would solve this? Best, Alex