Society of Robots - Robot Forum

Software => Software => Topic started by: HDL_CinC_Dragon on March 05, 2008, 10:34:21 PM

Title: Modulus function?
Post 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?
Title: Re: Modulus function?
Post by: garriwilson on March 05, 2008, 10:44:50 PM
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
Title: Re: Modulus function?
Post by: hazzer123 on March 06, 2008, 01:29:05 AM
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.
Title: Re: Modulus function?
Post by: paulstreats on March 06, 2008, 05:25:52 AM
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)
Title: Re: Modulus function?
Post by: Tsukubadaisei on March 06, 2008, 08:19:10 AM
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;
}
Title: Re: Modulus function?
Post by: HDL_CinC_Dragon on March 06, 2008, 09:42:36 AM
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!