[Issue 3918] New: Parameter use before its use in an AndAnd expression with reals treats NaN as false
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 9 16:41:28 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3918
Summary: Parameter use before its use in an AndAnd expression
with reals treats NaN as false
Product: D
Version: 2.041
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: crimson.magus at gmail.com
--- Comment #0 from Aldo Nunez <crimson.magus at gmail.com> 2010-03-09 16:41:26 PST ---
NaN is supposed to be treated as true when implicitly converted to bool,
because it's not the same as zero. But, in the following case, the NaN is
treated as false.
- optimized build
- a variable of type real with value NaN
- the variable is used in an AndAnd (&&) or OrOr (||) expression
- the variable is used before the AndAnd (&&) or OrOr (||) expression
I assume this happens anywhere a real is turned into a bool, but I haven't
checked.
Here's a sample program:
import std.stdio;
void Do( float t, real u )
{
writeln( u );
writeln( t && u );
}
void Do2( real t, float u )
{
writeln( t );
writeln( t && u );
}
void main( string[] args )
{
Do( float.nan, real.nan );
Do2( real.nan, float.nan );
}
In the function calls to both Do and Do2, the result is "false". It should be
"true". Commenting out "writeln( u )" and "writeln( t )" also make the results
"true".
Looking at the assembly code, I noticed that the cause seems to be an
instruction that's left out when the program is optimized.
Unoptimized (right):
00403C0D fld tbyte ptr [esp+8]
00403C11 fldz
00403C13 fucompp
00403C15 fnstsw ax
00403C17 sahf
00403C18 jne 00403C20
00403C1A jp 00403C20
Optimized (wrong):
00403C1E fld tbyte ptr [esp+8]
00403C22 fldz
00403C24 fucompp
00403C26 fnstsw ax
00403C28 sahf
00403C29 jne 00403C2F
The JP instruction is missing. As a result, we'll fall thru to where EAX is
cleared, and the result turns into false.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list