Created attachment 587
test case with comments
I've observed that these are the rules for explicitly casting floating point
numbers to bool:
- finite real numbers > -1 and < 1 are false
- all other real number values are true (including NaN)
- all imaginary numbers are false, since their real part is 0
- complex numbers as bool are the same as their real part as bool
I've noticed that the rules for implicitly casting floating point numbers to
bool, as in the expression (a && b), is different in several ways:
- real 0 and -0 are false
- all other finite real numbers > -1 and < 1 are *true*
- all other real number values are true (including NaN)
- imaginary 0 and -0 are false
- finite imaginary numbers > -1 and < 1 are *true*
- all other real number values are *true* (including NaN)
- complex numbers as bool are the same as the real *or* imaginary part as bool
under this new scheme. If either evaluates to true, then the complex is true.
There should be a single set of rules used for both cases.
As it is, I don't know which part of each set is right.
Comment #1 by nick — 2024-06-03T15:16:00Z
> - finite real numbers > -1 and < 1 are false
That is not the case, at least for all compilers currently on run.dlang.io:
static assert(cast(bool) 0.1f);
Built-in complex numbers are now deprecated.
Comment #2 by robert.schadek — 2024-12-13T17:51:43Z