go away spammer

Author Topic: Modulus function?  (Read 4070 times)

0 Members and 1 Guest are viewing this topic.

Offline HDL_CinC_DragonTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,261
  • Helpful? 5
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

Offline garriwilson

  • Supreme Robot
  • *****
  • Posts: 345
  • Helpful? 0
Re: Modulus function?
« Reply #1 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
« Last Edit: March 05, 2008, 10:45:28 PM by garriwilson »

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
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

  • Guest
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


Offline Tsukubadaisei

  • Robot Overlord
  • ****
  • Posts: 293
  • Helpful? 0
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)

Offline HDL_CinC_DragonTopic starter

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

 


Get Your Ad Here

data_list