Tushar Joshi
Tushar Joshi

Reputation: 55

System dependent limitations for code

With the function:

int five(int n)
{
    if ((n%5)==0)
        return 1;
    else
        return 0;
}

Why are the limitations of this positive numbers only even if there is no remainder?

Upvotes: 0

Views: 125

Answers (1)

William Pursell
William Pursell

Reputation: 212248

for n == -2, some hardware will compute n%5 as 3, while other hardware evaluates it as 2. To accommodate that , the standard leaves % ambiguous for negative values.

Upvotes: 2

Related Questions