Jump to content
JRJ

How To Do A Real Modulus

Recommended Posts

Is there a good way to do a proper modulus ( remainder) calculation eg: intvar = intvar%10 ?

according to the manual 19%10 =1 in boostc, but everywhere else it's 9, and I need it to be so.

This is the only C implementation I've ever seen that a modulus is a binary operator! :huh:

Heck- While I'm at it- it's the only implementation i've seen where basic arithmentic operators aren't threadsafe! :huh::huh:

Share this post


Link to post
Share on other sites

JRJ,

Is there a good way to do a proper modulus ( remainder) calculation eg: intvar = intvar%10 ?

according to the manual 19%10 =1 in boostc, but everywhere else it's 9, and I need it to be so.

Which part of the manual are you looking at??

 

int x;

x = 19%10; // give a result of 9

 

This is the only C implementation I've ever seen that a modulus is a binary operator! :huh:

Heck- While I'm at it- it's the only implementation i've seen where basic arithmentic operators aren't threadsafe! :huh::huh:

This limitation is because PICs don't have a stack like other processors. This means that local variables are create on a software stack (determined when your code is linked), this makes functions non-reenterant.

So any function may cause corruption problems if called in both main and interrupt threads.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...