Small Basic: Remainder with Negative Numbers


The Remainder(x,y) method’s usually used when both x and y are positive integers. Although Small Basic accepts any values you pass in, negative numbers might get confusing when you see the result. Look for the negative results in these examples:

Math.Remainder( -100,   15) ' Returns -10

Math.Remainder(  100,  -15) ' Returns 10

Math.Remainder(  -15,  100) ' Returns -15

Math.Remainder(   15, -100) ' Returns  15

Math.Remainder(   15,  100) ' Returns  15

Math.Remainder(  5.0,  3.5) ' Returns  1.5

Math.Remainder( -5.0, -3.5) ' Returns -1.5

Math.Remainder( -3.5, -5.0) ' Returns -3.5

The remainder’s negative only if the dividend is negative (the first number). We don’t want to confuse you anymore, so we recommend that you only use this method with positive integers.

 

Go to http://blogs.msdn.com/SmallBasic to download Small Basic for free and learn all about it!   

 

Small and Basically yours,

   - Majed Marji & Ed Price

Comments (1)

  1. Computers Today (part 1 of 6)

    blogs.msdn.com/…/computers-today.aspx

    …..

    CS SPOTLIGHT: Girls in computer programming… why it matters!!!

    blogs.msdn.com/…/cs-spotlight-girls-in-computer-programming-why-it-matters.aspx

    Computational Thinking – Videos & Papers by Jeannette Wing

    blogs.msdn.com/…/computational-thinking-videos-amp-papers-by-jeannette-wing.aspx

Skip to main content