Double compare operation not assigned correctly
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Double compare operation not assigned correctly

  1. #1
    Join Date
    Jun 2009
    Posts
    2

    Double compare operation not assigned correctly

    This is my first thread so bear with me...

    I have a comparison operation between two doubles:
    code:
    Code:
    1.	double lowX=  low.X // value is 2800000.000
    2.	double highX=  high.X // value is 2872000.000
    
    3.	bool result  = lowX <= highX // result false.   
    4.	result  = lowX <= highX // result true.
    And no matter what is the value of the doubles the result is false.
    Now the weird part is that if I use a VS7 immediate window and evalute "lowX <= highX" the result is true.
    If I have a break point and move the running line (yellow arrow) for the SECOND time on line 3 it also becomes true.
    I think that result is the first bool assignment in the code because other bool operation in later parts of the code works just fine.
    I am afraid there is something wrong with the stack. (Maybe the result doesn't really assigned to the bool result), But have no clue how to approach it.
    Thanks in Advance

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Double compare operation not assigned correctly

    your code is incomplete. What type is low.X and high.X? This code below compiles and returns the expected results:

    Code:
    	double lowX=  2800000.000;
    	double highX=  2872000.000;
    
    	bool result = lowX <= highX;  //true
    	result = lowX <= highX;  //true
    	result = highX <= lowX;  //false
    Please include exact code that cause your behavior. what you've posted works fine.

  3. #3
    Join Date
    Jun 2009
    Posts
    2

    Re: Double compare operation not assigned correctly

    low and high are essentially
    Code:
    struct point
    {
         double x;
         double y;
    }
    I will try to post the complete code
    but the general idea is like this

    Code:
    box::box(const point low, const point high)
    {
    	ASSERT(low.x <= high.x);
    	ASSERT(low.y <= high.y);
    }
    While I checked the problem i broke it down to my previous post...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center