Author Topic: Modulus function?  (Read 3186 times)

0 Members and 1 Guest are viewing this topic.

HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
Modulus function?
« 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?
United States Marine Corps
Infantry
Returns to society: 2014JAN11

garriwilson

• Supreme Robot
• Posts: 345
Re: Modulus function?
« Reply #1 on: March 05, 2008, 10:44:50 PM »
Lol I shouldn't even come close to programming... yet

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
« Last Edit: March 05, 2008, 10:45:28 PM by garriwilson »

hazzer123

• Supreme Robot
• Posts: 460
Re: Modulus function?
« Reply #2 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.
Imperial College Robotics Society
www.icrobotics.co.uk

paulstreats

• Supreme Robot
• Posts: 1,381
Re: Modulus function?
« Reply #3 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

• Robot Overlord
• Posts: 293
Re: Modulus function?
« Reply #4 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;
}
A.I.(yes those are my initials)

HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261