surepic
January 12, 2018, 1:19am
#1
First time decide to use modulo "%" operator and got confused.

a=17
b=1

17%1=1 as per Arduino

but formula is a-b*(a/b)

so step1:17/1=17
step2:1*17=17
step3:17-17=0

from where that 1 is coming from ?

UPDATE: put 9/8 in brackets and figured out what was confusing me.
whole expression is:
(7+10)%9/8

I guess because of left to right rule as % and / have same precedence first its doing % then division
i.e.
17%9=8
then 8/8 =1

Koepel
January 12, 2018, 2:17am
#2
Always make clear what you are doing. Never make someone reading the code or the compiler guess what is going on.

I have even a problem with "%9/8", I would use one of these:

( 7 + 10 ) % ( 9 / 8 )
( ( 7 + 10 ) % 9 ) / 8

surepic:
17%1=1 as per Arduino

What? Anything modulo 1 is zero. The C '%' is not a modulo operator, it is a remainder operator. This matters when you start using it with negative numbers. Anything divided by 1 is equal to itself with a remainder of zero.