Thread overview | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 27, 2015 Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 |
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:
> Any idea what i am doing wrong?
> https://www.youtube.com/watch?v=j_VCa-5VeP8
You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom, so I can't read the code...
|
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to jkpl | On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: > On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: >> Any idea what i am doing wrong? >> https://www.youtube.com/watch?v=j_VCa-5VeP8 > > You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom, so I can't read the code... Sry: Vector3D v = ray.origin.sub(this.center).normalize(); double a = ray.direction.dot(ray.direction); double b = 2.0 * ray.direction.dot(v); double c = v.dot(v) - (this.radius * this.radius); double discriminant = (b*b) - (4.0*a*c); 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; } |
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | 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
|
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SimonN | 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.
|
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | On Sunday, 27 December 2015 at 16:41:10 UTC, TheDGuy wrote:
> It looks like the debugger is not working correctly because i changed the code to this:
> [...]
> and the same problem appears.
I can't watch youtube here. What numbers does your input generate? Which 'if' doesn't fire? What results would you like instead?
-- Simon
|
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SimonN | On Sunday, 27 December 2015 at 16:48:44 UTC, SimonN wrote:
> On Sunday, 27 December 2015 at 16:41:10 UTC, TheDGuy wrote:
>> It looks like the debugger is not working correctly because i changed the code to this:
>> [...]
>> and the same problem appears.
>
> I can't watch youtube here. What numbers does your input generate? Which 'if' doesn't fire? What results would you like instead?
>
> -- Simon
I don't understand why my program goes into the if statement if the debugger shows, that the variable "discriminant" is below zero even though:
"if(discriminant > 0)"?
|
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | On Sunday, 27 December 2015 at 16:52:39 UTC, TheDGuy wrote:
> I don't understand why my program goes into the if statement if the debugger shows, that the variable "discriminant" is below zero even though:
>
> "if(discriminant > 0)"?
I have a hard time believing this. Does the problem persist if you swap out the entire control flow, beginning with that line, with the following?
if (discriminant > 0)
writeln("bigger than zero");
else
writeln("not entering the 'if'");
|
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: > Any idea what i am doing wrong? > https://www.youtube.com/watch?v=j_VCa-5VeP8 Tell me one thing, what is the value returned? Well It's working here: http://dpaste.dzfl.pl/18b27ea26b08 Maybe you would like to change the code above to look like yours and see what happens? Bubba. |
December 27, 2015 Re: Variable below zero but if statement doesn't grab? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bubbasaur | On Sunday, 27 December 2015 at 18:03:16 UTC, Bubbasaur wrote:
> On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:
>> Any idea what i am doing wrong?
>> https://www.youtube.com/watch?v=j_VCa-5VeP8
>
> Tell me one thing, what is the value returned?
>
>
> Well It's working here: http://dpaste.dzfl.pl/18b27ea26b08
>
> Maybe you would like to change the code above to look like yours and see what happens?
>
> Bubba.
Okay, thanks. It actually returned the right value but it looked like as if it would jump into the 2nd if-statement (as you can see on the video). Strange...
|
Copyright © 1999-2021 by the D Language Foundation