Pages: [1]   Go Down
Author Topic: modulo with negative int  (Read 405 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having some difficulties in cycling between a range of value..

int c = 0;
int length = 4;
c = -1 % length;

If I use this code I get -1 as result..if I use "unsigned" for c, I get 65535.
I'd like to get 3: (,or.r_qf.&bvm=bv.45512109,d.ZWU&fp=eb10b05648b700fa&biw=1440&bih=755)

If I'm not wrong I used to use % to get always a number in the range of the divisor, both when using negative or positive dividend..
what I'm missing?

Sydney, Australia
Offline Offline
Edison Member
Karma: 33
Posts: 1287
Big things come in large packages
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Intro paragraph gives you the answer.

Moderator edit: Tags removed
« Last Edit: April 22, 2013, 05:25:18 am by AWOL » Logged

Arduino libraries
Parola hardware & library

Pages: [1]   Go Up
Jump to: