# Difference in ADA Remainder Operators?

Page 1 of 1

## 2 Replies - 2031 Views - Last Post: 20 November 2013 - 04:59 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=334158&amp;s=33cbca5d4a8e67f98a8c14ca0befcf37&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 AnalyticLunatic

• D.I.C Lover

Reputation: 226
• Posts: 1,052
• Joined: 25-June 12

# Difference in ADA Remainder Operators?

Posted 15 November 2013 - 06:09 PM

So, as I understand it, the ADA programming language provides 2 remainder operators (along with a whole mess of allowable overloading for most operators). I'm having difficulty grasping the difference between the 2 remainder operators. I looked over this WikiBooks page I came across, but I don't think I'm making the light bulb turn on yet.

Can anyone explain this a little better to me?

Is This A Good Question/Topic? 0

## Replies To: Difference in ADA Remainder Operators?

### #2 mojo666

Reputation: 397
• Posts: 859
• Joined: 27-June 09

## Re: Difference in ADA Remainder Operators?

Posted 18 November 2013 - 01:48 PM

A mod B and A rem B are the same for positive integers A. The difference occurs when A is negative. mod will continue the looping pattern leaving only positive results. rem on the other hand will give negative results that are more of a reflection of the positive A's

for example

```N      |-6|-5|-4|-3|-2|-1| 0| 1| 2| 3| 4| 5| 6|
----------------------------------------------
N mod 3| 0| 1| 2| 0| 1| 2| 0| 1| 2| 0| 1| 2| 0|
----------------------------------------------
N rem 3| 0|-2|-1| 0|-2|-1| 0| 1| 2| 0| 1| 2| 0|
```

The reason for this is that mod technically returns a label representing a group of numbers. Every nth number is congruent (mod n). We say that -6,-3,0,3,and 6 are congruent (mod 3) thus they belong to the same congruency class. It is somewhat convenient to chose 0 for the label of this class. Remainder is just the calculation of what is left over after integer division is performed. So a negative number will have a negative leftover.

This post has been edited by mojo666: 18 November 2013 - 01:52 PM

### #3 turboscrew

Reputation: 133
• Posts: 894
• Joined: 03-April 12

## Re: Difference in ADA Remainder Operators?

Posted 20 November 2013 - 04:59 AM

Nice. Someone else knows the difference between reminder and modulus too.
I have been yelling about that on many C-forums, when people don't realize that "%" is reminder, not modulus.

In C (and C++) the "%" operator is called "mod" or "modulus", but the explanation is usually like "returns the remainder of expr1 divided by expr2".