D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4691 - Incorrect comparison of double and long
Summary: Incorrect comparison of double and long
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-08-20 12:15 UTC by Walter Bright
Modified: 2015-06-09 05:11 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2010-08-20 12:15:45 UTC
import std.c.stdio;

struct UN
{
   double         dd;
   long  ll;
}

string cmp( UN * pU )
{
   return pU.dd >= pU.ll ? "OK" : "ERRROR";
}

int main()
{
   static UN u = { 10.50, 10 };
   printf( "%.*s\n", cmp( &u ) );
   return 0;
}
Comment 1 bearophile_hugs 2010-08-20 13:06:56 UTC
Reduced test case:


double d = 1.5;
long l = 1;
void main() {
    assert(d >= l);
}
Comment 2 Walter Bright 2010-08-21 16:51:55 UTC
http://www.dsource.org/projects/dmd/changeset/622