Re: Don't compare zero exponentials in strings as equal

From: Date: Thu, 04 Mar 2021 19:26:46 +0000
Subject: Re: Don't compare zero exponentials in strings as equal
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-113389@lists.php.net to get a copy of this message
On 04/03/2021 13:17, Nikita Popov wrote:
A disadvantage of narrowing the definition in such a fashion is that it introduces a discrepancy with (float) casts. I believe these currently recognize the same values, with the exception that (float) discards trailing garbage.
I don't think that's a big problem; as you say, explicit casts are already more lax than implicit ones, and that's always going to be the case in some sense, because they never "fail". Opinions may vary, though.
Another disadvantage is that exponential notation is commonly returned for large numbers by various data source -- e.g. if you stored a large float in a database, I'd expect you'd get it back in exponential notation (if you get it back as a string). This means that your code could suddenly break because the range of a value passes some heuristic threshold for how it gets printed.
That may be a more compelling reason, at least given backwards compatibility requirements. I don't know how common that is, but it certainly sounds plausible. Regards, -- Rowan Tommins [IMSoP]

Thread (16 messages)

« previous php.internals (#113389) next »