www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Variable below zero but if statement doesn't grab?

reply TheDGuy <loder.feuer googlemail.com> writes:
Any idea what i am doing wrong?
https://www.youtube.com/watch?v=j_VCa-5VeP8
Dec 27 2015
next sibling parent reply jkpl <jkpl nowhere.de> writes:
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...
Dec 27 2015
next sibling parent reply TheDGuy <loder.feuer googlemail.com> writes:
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; }
Dec 27 2015
parent reply SimonN <eiderdaus gmail.com> writes:
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
Dec 27 2015
parent reply TheDGuy <loder.feuer googlemail.com> writes:
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.
Dec 27 2015
parent reply SimonN <eiderdaus gmail.com> writes:
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
Dec 27 2015
parent reply TheDGuy <loder.feuer googlemail.com> writes:
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)"?
Dec 27 2015
parent SimonN <eiderdaus gmail.com> writes:
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'");
Dec 27 2015
prev sibling parent reply jkpl <jkpl nowhere.de> writes:
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...
I work more or less lying on a futon. Desks are so cheesy...
Dec 28 2015
parent reply Basile B. <b2.temp gmx.com> writes:
On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
Dec 28 2015
parent reply jkpl <jkpl jkpl.de> writes:
On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
Dec 28 2015
next sibling parent reply jkpl <jkpl jkpl.de> writes:
On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=g7qx5oYdOEA tous fashos: juif, chrétien, musulmans,... Il n'y a bien que les communistes qui ont compris que les religions c'est de la merde.
Dec 28 2015
parent reply jkpl <jkpl jkpl.de> writes:
On Monday, 28 December 2015 at 18:12:24 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=g7qx5oYdOEA tous fashos: juif, chrétien, musulmans,... Il n'y a bien que les communistes qui ont compris que les religions c'est de la merde.
Also, european people should ask themselves why they stick on the US culture since 60 years, while actually Russians freed Berlin.
Dec 28 2015
parent reply jkpl <jkpl jkpl.de> writes:
On Monday, 28 December 2015 at 18:33:16 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 18:12:24 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=g7qx5oYdOEA tous fashos: juif, chrétien, musulmans,... Il n'y a bien que les communistes qui ont compris que les religions c'est de la merde.
Also, european people should ask themselves why they stick on the US culture since 60 years, while actually Russians freed Berlin.
One last thing. Tough guy ? https://www.youtube.com/watch?v=1igvrZ0KosA
Dec 28 2015
parent jkpl <jkpl jkpl.de> writes:
On Monday, 28 December 2015 at 19:22:00 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 18:33:16 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 18:12:24 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=g7qx5oYdOEA tous fashos: juif, chrétien, musulmans,... Il n'y a bien que les communistes qui ont compris que les religions c'est de la merde.
Also, european people should ask themselves why they stick on the US culture since 60 years, while actually Russians freed Berlin.
One last thing. Tough guy ? https://www.youtube.com/watch?v=1igvrZ0KosA
I always try to find a link to the scene, in south america: "And finally I've done what I always done...". I never find it. It's probably because judgment defaits us: https://www.youtube.com/watch?v=xNRBajLM8_4 We want to show something, but we're always near, no so far, not close to our idea. It exists but we cant find a reference to the perfect representation of the idea...
Dec 28 2015
prev sibling next sibling parent Marcel mauss <Marcel mauss.de> writes:
On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
thumb up. I dont think that you have won. Monotheism is a 2000 year old failure. Many god haven't solidarized us...only one failed.
Dec 31 2015
prev sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=YgSPaXgAdzE I'm a loser baby, so why don't you leave me ? You luv losers ? And you don't leave them ? Nurse syndrom.
Jan 05
parent reply Basile B. <b2.temp gmx.com> writes:
On Tuesday, 5 January 2016 at 23:52:05 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=YgSPaXgAdzE I'm a loser baby, so why don't you leave me ? You luv losers ? And you don't leave them ? Nurse syndrom.
to the MI6: It's a english daddy boy who tought me what is a papirosn https://en.wikipedia.org/wiki/Belomorkanal TIP to englishmen: you should learn how to behave in France.
Jan 15
parent Basile B. <b2.temp gmx.com> writes:
On Friday, 15 January 2016 at 22:16:09 UTC, Basile B. wrote:
 On Tuesday, 5 January 2016 at 23:52:05 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:
 On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:
 On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:
 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...
I work more or less lying on a futon. Desks are so cheesy...
Anarchism is comfy...
when I'm tired with the conformism I just let my head go on the pillow and I sleep... (snoring) Even if I dont't think that you have won: https://youtu.be/Uj_7kTwRMKE?t=2m35s
https://www.youtube.com/watch?v=YgSPaXgAdzE I'm a loser baby, so why don't you leave me ? You luv losers ? And you don't leave them ? Nurse syndrom.
to the MI6: It's a english daddy boy who tought me what is a papirosn https://en.wikipedia.org/wiki/Belomorkanal TIP to englishmen: you should learn how to behave in France.
Like the whole world can see today, you have took an anwesome decision in 1948. Well managed. very clever I'd say...
Jan 15
prev sibling next sibling parent reply Bubbasaur <bubba gmail.com> writes:
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.
Dec 27 2015
parent TheDGuy <loder.feuer googlemail.com> writes:
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...
Dec 27 2015
prev sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/27/2015 07:53 AM, TheDGuy wrote:
 Any idea what i am doing wrong?
 https://www.youtube.com/watch?v=j_VCa-5VeP8
YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste. There is no guarantee that such threads will be useful forever. :) For me, sample code should be right here, and it should be short enough to practically be here. Ali
Dec 27 2015
parent reply TheDGuy <loder.feuer googlemail.com> writes:
On Sunday, 27 December 2015 at 22:51:27 UTC, Ali Çehreli wrote:
 On 12/27/2015 07:53 AM, TheDGuy wrote:
 Any idea what i am doing wrong?
 https://www.youtube.com/watch?v=j_VCa-5VeP8
YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste. There is no guarantee that such threads will be useful forever. :) For me, sample code should be right here, and it should be short enough to practically be here. Ali
I deleted the video because the problem was solved, it was neither a problem with the single '&' nor with my code it just showed a strange behaviour while debugging but the function returned the right value. Sample code is in my second post.
Dec 27 2015
parent reply rumbu <rumbu rumbu.ro> writes:
On Sunday, 27 December 2015 at 23:24:55 UTC, TheDGuy wrote:
 On Sunday, 27 December 2015 at 22:51:27 UTC, Ali Çehreli wrote:
 On 12/27/2015 07:53 AM, TheDGuy wrote:
 Any idea what i am doing wrong?
 https://www.youtube.com/watch?v=j_VCa-5VeP8
YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste. There is no guarantee that such threads will be useful forever. :) For me, sample code should be right here, and it should be short enough to practically be here. Ali
I deleted the video because the problem was solved, it was neither a problem with the single '&' nor with my code it just showed a strange behaviour while debugging but the function returned the right value. Sample code is in my second post.
Get used to it :) Unfortunately, DMD is not emitting the best debug information. The program flow is correct, but the line info is not, that's why the execution step will not be triggered in the real location of the source code. The simplest example is this: import std.stdio; void foo(int x) { if (x > 0) //step 1, correct { writeln("bigger"); //step 2, correct } else { writeln("lower"); //step 3, wrong } } int main(string[] argv) { foo(20); //breakpoint with step in return 0; } If you really want to confuse the debugger, write some asserts or contracts here and there and your program will be impossible to debug :)
Dec 28 2015
parent TheDGuy <loder.feuer googlemail.com> writes:
 Get used to it :) Unfortunately, DMD is not emitting the best 
 debug information. The program flow is correct, but the line 
 info is not, that's why the execution step will not be 
 triggered in the real location of the source code.

 The simplest example is this:

 import std.stdio;

 void foo(int x)
 {
     if (x > 0)              //step 1, correct
     {
         writeln("bigger");  //step 2, correct
     }
     else
     {
         writeln("lower");   //step 3, wrong
     }
 }

 int main(string[] argv)
 {
     foo(20);   //breakpoint with step in
     return 0;
 }

 If you really want to confuse the debugger, write some asserts 
 or contracts here and there and your program will be impossible 
 to debug :)
So, do you have any information if there will be a fix to this? It is really hard (at least for me) to work with a language which doesn't feature a working debugger...
Dec 28 2015