Div, MOD question

Post your requests and ideas on the future development of mikroBasic.
Post Reply
Author
Message
beginner
Posts: 5
Joined: 10 Dec 2006 20:16

Div, MOD question

#1 Post by beginner » 10 Dec 2006 20:31

A div B is the value of A divided by B rounded down to the nearest integer. The mod operator returns the remainder obtained by dividing its operands. In other words,

X mod Y = X - (X div Y) * Y.

Hi Guys and Girls

The extract from the manual on DIV and MOD, i understand the sentences but dont understand the formula or how to put this into Basic.

Could some one show me how this is put into Basic and what i would expect to see in the Watch box.

Something simple please like 5 / 2 = 2.5

Any help much appreciated.

bcz
Posts: 16
Joined: 07 Nov 2008 18:34

Re: Div, MOD question

#2 Post by bcz » 11 Nov 2008 12:25

[quote="beginner"]A div B is the value of A divided by B rounded down to the nearest integer. The mod operator returns the remainder obtained by dividing its operands. In other words,

X mod Y = X - (X div Y) * Y.

/quote]

I am puzzled by the above.
Let X =5 and B = 2
X div Y = 5 div 2 = int(2.5) = 2
therefore
(X div Y) * Y = 2 * 2 = 4
and
X - (X div Y) * Y = 5 - 4 = 1
The fractional part (remainder) of 5/2 is 0.5
What now?

bcz
Posts: 16
Joined: 07 Nov 2008 18:34

Re: Div, MOD question

#3 Post by bcz » 11 Nov 2008 12:32

Let X =5 and B = 2

Sorry about the mistake in my previous post.
I ment to say

Y = 2

Post Reply

Return to “mikroBasic Wish List”