Variable below zero but if statement doesn't grab?

TheDGuy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 27 08:41:10 PST 2015


On Sunday, 27 December 2015 at 16:39:18 UTC, SimonN wrote:
> On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote:
>> Sry:
>> 			if((x1 < 0) & (x2 >= 0)){
>
> This looks like a bug, with & instead of &&.
>
> -- Simon

It looks like the debugger is not working correctly because i 
changed the code to this:

		if(discriminant > 0){
			double x1 = (-b - sqrt(discriminant)) / (2.0*a);
			double x2 = (-b + sqrt(discriminant)) / (2.0*a);
			if((x1 >= 0) && (x2 >= 0)){
				return x1;
			}
			if((x1 < 0) && (x2 >= 0)){
				return x2;
			}
			return -1.0;
		} else{
			return -1.0;
		}

and the same problem appears.


More information about the Digitalmars-d-learn mailing list