ilan Expert Licensed User Longtime User Jul 27, 2020 #1 hi i dont know if it is a bug but it seems to me to be one. if i use before the MOD function a calculation without () i get a different result then if i would use () like this code here: B4X: For i = 0 To 7 Dim num As Int = i + 2 Mod 7 Log(num) Next Waiting for debugger to connect... Program started. 2 3 4 5 6 7 8 9 Click to expand... but this is correct: B4X: For i = 0 To 7 Dim num As Int = (i + 2) Mod 7 Log(num) Next Waiting for debugger to connect... Program started. 2 3 4 5 6 0 1 2 Click to expand... hmmm... what i understand is that MOD comes before +/- so the calculation looks now like this: i + (2 mod 7) but it doesnot make sense when we use mod in coding. or am i wrong?
hi i dont know if it is a bug but it seems to me to be one. if i use before the MOD function a calculation without () i get a different result then if i would use () like this code here: B4X: For i = 0 To 7 Dim num As Int = i + 2 Mod 7 Log(num) Next Waiting for debugger to connect... Program started. 2 3 4 5 6 7 8 9 Click to expand... but this is correct: B4X: For i = 0 To 7 Dim num As Int = (i + 2) Mod 7 Log(num) Next Waiting for debugger to connect... Program started. 2 3 4 5 6 0 1 2 Click to expand... hmmm... what i understand is that MOD comes before +/- so the calculation looks now like this: i + (2 mod 7) but it doesnot make sense when we use mod in coding. or am i wrong?
ilan Expert Licensed User Longtime User Jul 27, 2020 #2 according to this explanation https://en.wikipedia.org/wiki/Modular_arithmetic modular calculation is always inside () so: 2 + 4 mod 2 = 2 + 4 (mod 2) if this is true then the mod function in b4x is incorrect.
according to this explanation https://en.wikipedia.org/wiki/Modular_arithmetic modular calculation is always inside () so: 2 + 4 mod 2 = 2 + 4 (mod 2) if this is true then the mod function in b4x is incorrect.
alwaysbusy Expert Licensed User Longtime User Jul 27, 2020 #3 I think it is correct. Mod is at the same level as * and / and they precede the + and - OperatorsPrecedence( )first (highest)not, ^, **secondand, mod, div, *, /thirdor, xor, +, -fourth=, <>, >, <, >=, <=fifth (lowest)
I think it is correct. Mod is at the same level as * and / and they precede the + and - OperatorsPrecedence( )first (highest)not, ^, **secondand, mod, div, *, /thirdor, xor, +, -fourth=, <>, >, <, >=, <=fifth (lowest)