Page 1 of 1

What about a DIV function? (solved)

Posted: Mon Dec 04, 2006 5:52 pm
by AND51
Hello!

Modulo already exists, but what do you think about a DIV function? This is a kind of division returning the number of how often y can be found in x. Sorry, but I don't know how to express that in english :lol:

What I mean is a kind of Integer-Division.

Just look at this

Code: Select all

a=25
b=7

Macro DIV(x, y)
	((x-x%y)/y)
EndMacro

; result will be 3, because: 25 / 7 = 3 + 4 / 7 (the rest, 4/7 will be ignored)
Debug DIV(a, b)

Posted: Mon Dec 04, 2006 6:21 pm
by ts-soft
It's not the same like this?

Code: Select all

a=25
b=7

; result will be 3
Debug a / b

Posted: Mon Dec 04, 2006 6:28 pm
by Trond
PB selects between DIV and / automatically using the following rules:
  • If one of the operands is a float or double, then / is used
  • If the result of the expression is predicted to be a float (ie f.f = a/b) then / is used
  • Else, DIV is used

Code: Select all

a = 25 
b = 7 
f.f = 25
g.f = 7

Debug a/b           ; <- DIV
Debug a/(b+0)       ; <- DIV
Debug (a+0)/(b)     ; <- DIV
Debug (a+0)/(b+0)   ; <- DIV
Debug (a+0)/(b+0)   ; <- DIV

Debug a/(b+0.)      ; <- /
Debug (a+0.)/b      ; <- /
Debug (a+0.)/(b+0.) ; <- /

Debug f/g           ; <- /
Debug Int(f)/g      ; <- /
Debug f/Int(g)      ; <- /
Debug Int(f)/Int(g) ; <- DIV