Society of Robots - Robot Forum
Software => Software => Topic started by: HDL_CinC_Dragon on March 05, 2008, 10:34:21 PM
-
Is there a modulus function I can put in my program? I know in C++ the modulus math function is simply % where the multiplication function would be * and division be /. It doesnt seem to do anything when I try this... Ideas?
-
Lol I shouldn't even come close to programming... yet :D
But, just a suggestion, maybe you should put the numbers in parentheses? (2)(5)=12 :-\ lol I know it's 10... or (10)/(2) = 5 yay I got it right ! I'm Einstein.
P.S. e = mc2
-
When im programming PICs, to use modulus i have to write -
pmod(number, divisor);
Its written like a function.
You should check out the datasheet for the maths functions in your library.
-
I know that it isnt an answer to your question but i think that this is worth mentioning:-
The latest pic18's that have been released by microchip have hardware multipliers built in now, meaning that 8bit multiplications take only 1 clock cycle rather than relying on the compiler. Here is a datasheet table from the f2525
(http://www.uk-robotics.co.uk/misc/pictbl.jpg)
-
Is there a modulus function I can put in my program? I know in C++ the modulus math function is simply % where the multiplication function would be * and division be /. It doesnt seem to do anything when I try this... Ideas?
I could not undertand your question very well but if you dont know how to use modulus operator(not function) then here we go:
12%5=2
only that and you write just like that in C or C++ or C# or Java.
There is also a small probability of the modulus operator not being implemented in your compiler. In that case you have to create your function by using the Euclidean Algorithm:
int modulus(x,y){
while(x>=x){
x-=y;
}
return x;
}
-
Thanks Tsuk, Thats exactly what I needed. I know how to use the modulus operator(couldnt think of the work before) in Java and C/C++/C# but when I programmed it into my micro it wasnt working. Thanks!