www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3947] New: Implicit and explicit casting of floating point to bool produces different results

http://d.puremagic.com/issues/show_bug.cgi?id=3947

           Summary: Implicit and explicit casting of floating point to
                    bool produces different results
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: crimson.magus gmail.com



PST ---
Created an attachment (id=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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 13 2010