2 Replies - 977 Views - Last Post: 20 November 2013 - 04:59 AM Rate Topic: -----

#1 AnalyticLunatic  Icon User is offline

  • D.I.C Lover

Reputation: 218
  • View blog
  • Posts: 1,004
  • 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.

WikiBooks ADA Operators

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  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 337
  • View blog
  • Posts: 728
  • 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

Was This Post Helpful? 2
  • +
  • -

#3 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 609
  • 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".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1