Hello!
Well, this might be a bit out-of-topic, but somehow relates to here.
I'm trying to deal with calculating the sleeping time to the next minute at 0 second. So this is something between 0 and 59999 ms.
Hm, that's too easy, mod60000 calculates exactly this. However I can't figure out what am I doing wrong:
uint32_t a = 21625 - 26250;
uint32_t b = a % 60000U;
uint32_t c = 60000U - b;
printf("data: a=%d, b=%d, c=%d\n\r", (int)a,(int)b,(int)c);
//prints "data: a=-4625, b=-22865, c=17329"
I know that printf uses void* pointers and casts them to the defined format.
So far, 'a' is alright.
However, for 'b', I have no idea. I'd like it to be exactly 55375. (I know about C89's truncate towards zero, but how could I overcome of that in avr-gcc?) Why is b -22865?
And well, for 'c', that's alright too.
A feel confused of b's current value. Any explanation would be very helpful, I guess.
Thanks!