Blazemaguire
Senior Member
Hello,
This is my first forage into Picaxe maths, and I'm struggling to understand what is happening - I've read manual 2 regards variable maths, but It doesn't seem to explain in enough detail to cover my issue below.
Hoping you can shed some light.
(I won't bore you with the back story of why I'm doing it, but it's in essence the starting point for working out velocity based on number of input pulses recieved in given amount of time) I'm trying to do some simple remainder and quotient maths, and just returning the answers into word variables that i'm checking via the sertxd command via simulation.
My code is:
main:
w1= 3
w2= 7
w3= w1/w2 ' should return quotient into w3
w4=w1//w2 ' should return remainder into w4
sertxd (#w3," Quot ",#w4," Rem") 'write word variables to serial terminal
pause 1000
w3=0 ' reset word variables
w4=0
goto main
In 'normal' maths, this should retain a quotient of '0' and a remainder of 428..... etc - Yet it returns qoutient ='0' and remainder = '3' on the serial window. - My question is, why do I get '3' for the remainder? - that is neither rounded up or down!? - I was expecting '4'... - I can't progress my maths any further, until I truly understand why this is happening.
There is obviously some reason for this, but I don't understand enough about PICAXE maths to know why this is... unless I'm looking in the wrong place, or just plain stupid, I can't see anything in manual 2 that explains why this is. - Can anyone shed any light? - Maths is not my strong suit on a good day, let alone the weird maths workarounds you have to do with micro controller maths.
Any pointers to get me started would be really appreciated!
Thanks
Rob
This is my first forage into Picaxe maths, and I'm struggling to understand what is happening - I've read manual 2 regards variable maths, but It doesn't seem to explain in enough detail to cover my issue below.
Hoping you can shed some light.
(I won't bore you with the back story of why I'm doing it, but it's in essence the starting point for working out velocity based on number of input pulses recieved in given amount of time) I'm trying to do some simple remainder and quotient maths, and just returning the answers into word variables that i'm checking via the sertxd command via simulation.
My code is:
main:
w1= 3
w2= 7
w3= w1/w2 ' should return quotient into w3
w4=w1//w2 ' should return remainder into w4
sertxd (#w3," Quot ",#w4," Rem") 'write word variables to serial terminal
pause 1000
w3=0 ' reset word variables
w4=0
goto main
In 'normal' maths, this should retain a quotient of '0' and a remainder of 428..... etc - Yet it returns qoutient ='0' and remainder = '3' on the serial window. - My question is, why do I get '3' for the remainder? - that is neither rounded up or down!? - I was expecting '4'... - I can't progress my maths any further, until I truly understand why this is happening.
There is obviously some reason for this, but I don't understand enough about PICAXE maths to know why this is... unless I'm looking in the wrong place, or just plain stupid, I can't see anything in manual 2 that explains why this is. - Can anyone shed any light? - Maths is not my strong suit on a good day, let alone the weird maths workarounds you have to do with micro controller maths.
Any pointers to get me started would be really appreciated!
Thanks
Rob