Bug 3947 – Implicit and explicit casting of floating point to bool produces different results

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-03-13T01:50:09Z
Last change time
2024-12-13T17:51:43Z
Keywords
spec
Assigned to
No Owner
Creator
Aldo Nunez
Moved to GitHub: dmd#18182 →

Attachments

IDFilenameSummaryContent-TypeSize
587imagBool.dtest case with commentsapplication/octet-stream7858

Comments

Comment #0 by aldonunez1 — 2010-03-13T01:50:09Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18182 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB