Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

## #1 2012-10-11 20:51:12

Harold
Guest

### Modulo

Can you help me with these two problem
-23 mod 5
23 mod -5
and,could you please explain modulo with nagetive number?

## #2 2012-10-11 21:20:23

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

If you use this formula you will have no problems with modulo.

Where

is called the floor function and is evaluated like this:

and

it always rounds down to the smallest integer.

Let's do the first one:

-23 mod 5

You are looking for r, the remainder. a = -23 and m is the modulo, in this case 5.

Now

So -23 mod 5 is 2.

You try the second one. Let me know what you get.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #3 2012-10-11 22:56:51

Harold
Guest

### Re: Modulo

It is -2,is nagetive number allowed as result?

## #4 2012-10-11 23:21:10

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

Yes, unless you are told it must be positive.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #5 2012-10-11 23:30:24

Harold
Guest

### Re: Modulo

Thank you^infinity

## #6 2012-10-12 00:07:52

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

You are welcome. Were you able to do the second problem?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #7 2012-10-12 00:50:15

bob bundy
Moderator
Registered: 2010-06-20
Posts: 7,979

### Re: Modulo

hi bobbym,

Yes he has (in post 3).  He got -2

The definition for modulo regarding + or - is uncertain.  See http://en.wikipedia.org/wiki/Modulo_operation

Harold ought to check how it has been defined by his teacher.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

## #8 2012-10-12 01:10:13

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

Yes he has (in post 3).  He got -2

I see that now. He got the right answer too.

Sometimes it has to be the same sign as the divisor. I gave him the one that gets the same answers as Wolfram would.

Unfortunately he skeddadled right after he solved it. I wanted to go a little deeper.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #9 2012-10-12 03:21:18

Harold
Guest

### Re: Modulo

Guys,I have another problem,my brother says that 23 mod -5 will be 3 as Euclidean division states a=bq+r and the division will be 23=(-5)*(-4)+3.

## #10 2012-10-12 04:15:27

bob bundy
Moderator
Registered: 2010-06-20
Posts: 7,979

### Re: Modulo

hi Harold,

In effect, that was my point in post 7.

The following are all equivalent mod 5

-12,  -7,  -2, 3, 8, 13, 18 ......

If you follow my link to Wiki you will see that two definitions are possible and there are even more variations amongst computer languages.

Your brother is right using the 'Euclidean division' definition ... under this no negatives are allowed.

Which is why I think you need to check with your teacher / tutor and see what definition is required.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

## #11 2012-10-12 20:30:24

Harold
Guest

### Re: Modulo

I am sorry to bug again but after you gave me the formula,i experimented a little and solution to -23 mod -5 results -43,is it correct

## #12 2012-10-12 21:24:25

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

I am getting -3 as the answer. Can I see what you have done?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #13 2012-10-12 21:47:16

bob bundy
Moderator
Registered: 2010-06-20
Posts: 7,979

### Re: Modulo

Looks like -23 - 20 = -43 rather than -23 + 20 = -3

There are a lot of minus signs to take account of.  Easy to slip up on that.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

## #14 2012-10-12 22:00:24

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

I am getting

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #15 2012-10-12 23:43:55

Harold
Guest

### Re: Modulo

You're right,i missed a minus sign,thank you a lot,you guys taught me a lot of things today.

## #16 2012-10-12 23:49:15

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi Harold;

Use a calculator to at least check.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #17 2012-10-13 19:51:07

bob bundy
Moderator
Registered: 2010-06-20
Posts: 7,979

### Re: Modulo

The formula should always give a value x, so that -m < x < m (assuming m is positive ... reverse the signs otherwise)

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

## #18 2012-10-13 21:37:55

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi bob;

If you did that what do you get for -65 mod -17?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #19 2012-10-13 21:57:00

bob bundy
Moderator
Registered: 2010-06-20
Posts: 7,979

### Re: Modulo

Good morning bobbym

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

## #20 2012-10-13 22:02:32

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi Bob;

Good Morning.

That is what I am getting too.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #21 2012-10-13 22:08:00

bob bundy
Moderator
Registered: 2010-06-20
Posts: 7,979

### Re: Modulo

My point was that Harold can eliminate obvious errors such as -43 on the grounds that it is out of range.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

## #22 2012-10-13 22:11:05

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Modulo

Hi;

Yes, it is an obvious error, the answer can never exceed m. In either direction.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline