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 https://blogs.msdn.com/SmallBasic to download Small Basic for free and learn all about it!   

 

Small and Basically yours,

   - Majed Marji & Ed Price