Re: [RFC brainstorm] Approximately equals operator
| From: | Iliya Miroslavov Iliev | Date: | Tue, 01 Apr 2025 07:40:43 +0000 |
| Subject: | Re: [RFC brainstorm] Approximately equals operator | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126995@lists.php.net to get a copy of this message | ||
> var_dump(random_int(1, 1) ~= 1.1); // true
This one cracked me :D Thanks Niels!
On Tue, Apr 1, 2025 at 5:48 AM Alexandru Pătrănescu <drealecs@gmail.com>
wrote:
>
>
> On Tue, Apr 1, 2025, 01:03 Niels Dossche <dossche.niels@gmail.com> wrote:
>
>> Hi internals!
>>
>> I'm excited to share what I've been working on!
>> I had an epiphany. I realized what we truly need to revolutionize PHP: a
>> new operator.
>>
>> Hear me out.
>> We live in an imperfect world, and we often approximate data, but neither
>>
== nor === are ideal
>> comparison operators to deal with these kinds of
>> data.
>>
>> Introducing: the "approximately equal" (or "approx-equal") operator
>> ~=
>> (to immitate the maths symbol ≃).
>> This combines the power of type coercion with approximating equality.
>> Who cares if things are actually equal, close enough amirite?
>>
>>
> Hi Niels,
>
> When I was reading it, I felt a bit unsure, but numbers related, it was
> making sense.
> When you got to strings with "This is a tpyo" ~= "This is a
> typo", I
> also remembered today it's 1st of April, so there's that...
>
> --
> Alex
>
--
Iliya Miroslavov Iliev
i.miroslavov@gmail.com