nfordbscndrd Well-Known Member Licensed User Longtime User Jun 19, 2011 #1 I've been looking and looking at the code below and can't figure out what I'm doing wrong, so I'm wondering if it could somehow be an error in B4A. The array NumTopCards() is an Integer. avgSpds is a Double. As you can see in the Logs Tab, NumTopCards(p, Spd) = 2 and avgSpds = 2.666, so the single-stepper should not get past the first line of code to the Log line and the highlighted line, but it obviously does???? I created the following test app and it performed as expected. Code: Dim i As Int Dim j As Double i = 2 j = 2.1 If j > i Then Msgbox("j is bigger","") End If
I've been looking and looking at the code below and can't figure out what I'm doing wrong, so I'm wondering if it could somehow be an error in B4A. The array NumTopCards() is an Integer. avgSpds is a Double. As you can see in the Logs Tab, NumTopCards(p, Spd) = 2 and avgSpds = 2.666, so the single-stepper should not get past the first line of code to the Log line and the highlighted line, but it obviously does???? I created the following test app and it performed as expected. Code: Dim i As Int Dim j As Double i = 2 j = 2.1 If j > i Then Msgbox("j is bigger","") End If
K kickaha Well-Known Member Licensed User Longtime User Jun 20, 2011 #2 Looks like it is the way numbers are dealt with internally (I remember seeing a post by Erel on that, but do not remember the details). Try this code to better see what is happening - although it does not show why! Code: Dim i As Int Dim j As Double Dim k As Double i = 2 j = 2.1 k = i If j > i Then Msgbox("j is bigger","") End If If i >= j Then Msgbox("i is bigger","") End If If k >= j Then Msgbox("is i still bigger - even as k","NO it is not") End If As a workround, use math Code: If (i - j) >= 0 Then Msgbox("i is bigger","Not using math!") End If Last edited: Jun 20, 2011
Looks like it is the way numbers are dealt with internally (I remember seeing a post by Erel on that, but do not remember the details). Try this code to better see what is happening - although it does not show why! Code: Dim i As Int Dim j As Double Dim k As Double i = 2 j = 2.1 k = i If j > i Then Msgbox("j is bigger","") End If If i >= j Then Msgbox("i is bigger","") End If If k >= j Then Msgbox("is i still bigger - even as k","NO it is not") End If As a workround, use math Code: If (i - j) >= 0 Then Msgbox("i is bigger","Not using math!") End If
nfordbscndrd Well-Known Member Licensed User Longtime User Jun 20, 2011 #3 Using math seems to do the trick. Thanks.
klaus Expert Licensed User Longtime User Jun 20, 2011 #4 Just a question, in your code you test with: AllQty(p, p, Spd) But in the Log() you look at: AllQty(p, AllOthers, Spd) Is this really what you are looking for ? Best regards.
Just a question, in your code you test with: AllQty(p, p, Spd) But in the Log() you look at: AllQty(p, AllOthers, Spd) Is this really what you are looking for ? Best regards.
agraham Expert Licensed User Longtime User Jun 20, 2011 #5 This looks like a subtle compiler bug to me For some reason the compiler is casting the Double to an Int when comparing //BA.debugLineNum = 49;BA.debugLine="If i = j Then"; if (_i== (int)(_j)) { Rather than just comparing them and letting the Java compiler promote the Int to a Double which happens if you reorder the variables in the comparison.. //BA.debugLineNum = 49;BA.debugLine="If j = i Then"; if (_j==_i) { @Erel - surely this is not intended behaviour?
This looks like a subtle compiler bug to me For some reason the compiler is casting the Double to an Int when comparing //BA.debugLineNum = 49;BA.debugLine="If i = j Then"; if (_i== (int)(_j)) { Rather than just comparing them and letting the Java compiler promote the Int to a Double which happens if you reorder the variables in the comparison.. //BA.debugLineNum = 49;BA.debugLine="If j = i Then"; if (_j==_i) { @Erel - surely this is not intended behaviour?
Erel B4X founder Staff member Licensed User Longtime User Jun 20, 2011 #6 This is a bug and it will be fixed in the next update. As agraham wrote you should change the order of variables and start with the double variable.
This is a bug and it will be fixed in the next update. As agraham wrote you should change the order of variables and start with the double variable.
nfordbscndrd Well-Known Member Licensed User Longtime User Jun 20, 2011 #7 klaus said: Just a question, in your code you test with: AllQty(p, p, Spd) But in the Log() you look at: AllQty(p, AllOthers, Spd) Is this really what you are looking for ? Click to expand... Yes, but thanks for asking. The top line of the code shown is Else If NumTopCards(p, Spd) >= avgSpds) _ and not shown is that avgSpds is AllQty(p, AllOthers, Spd) / numWithSpds, which is why I was Logging those two variables.
klaus said: Just a question, in your code you test with: AllQty(p, p, Spd) But in the Log() you look at: AllQty(p, AllOthers, Spd) Is this really what you are looking for ? Click to expand... Yes, but thanks for asking. The top line of the code shown is Else If NumTopCards(p, Spd) >= avgSpds) _ and not shown is that avgSpds is AllQty(p, AllOthers, Spd) / numWithSpds, which is why I was Logging those two variables.
nfordbscndrd Well-Known Member Licensed User Longtime User Jun 20, 2011 #8 Erel said: This is a bug and it will be fixed in the next update. As agraham wrote you should change the order of variables and start with the double variable. Click to expand... Thanks agraham and erel, and while I'm at it, if you notice in the screen shot in my original post, I get these apparently random red bars up and down the scroll bar. Are these glitches, or do they indicate something?
Erel said: This is a bug and it will be fixed in the next update. As agraham wrote you should change the order of variables and start with the double variable. Click to expand... Thanks agraham and erel, and while I'm at it, if you notice in the screen shot in my original post, I get these apparently random red bars up and down the scroll bar. Are these glitches, or do they indicate something?
agraham Expert Licensed User Longtime User Jun 20, 2011 #9 The red markers are where breakpoints are set that are not visible in the source code window. Double click or select a word and you get blue markers. Bookmarks are dark grey markers. Present execution point is a yellow marker.
The red markers are where breakpoints are set that are not visible in the source code window. Double click or select a word and you get blue markers. Bookmarks are dark grey markers. Present execution point is a yellow marker.
Erel B4X founder Staff member Licensed User Longtime User Jun 20, 2011 #10 Moving the scroll bar to an indicator will make it visible.