deprecate boolean evaluation of floating point and character types
Quirin Schroll
qs.il.paperinik at gmail.com
Thu May 16 17:50:39 UTC 2024
On Wednesday, 1 May 2024 at 10:01:29 UTC, Nick Treleaven wrote:
> On Tuesday, 30 April 2024 at 17:01:42 UTC, Basile B. wrote:
>> Generally there is a strong correlation between default
>> initialization and boolean evaluation to `false`.
>
> But the meaning of boolean evaluation of a number is to check
> if it is non-zero. That is well established from C.
Not well enough for JavaScript. Just tried it: `Boolean(0/0)`
gives `false`.
Deprecating floating-point to `bool` conversions (in conditions
or otherwise) would be correct, including `cast(bool)(x)`. What
the user wants, usually, is `!isNaN(x) && x != 0.0`. Writing out
`x != 0.0` isn’t that hard.
Also, `++x` is morally wrong for floating-point types.
More information about the dip.ideas
mailing list