What about a DIV function? (solved)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

What about a DIV function? (solved)

Post 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)
Last edited by AND51 on Mon Dec 04, 2006 6:36 pm, edited 1 time in total.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

It's not the same like this?

Code: Select all

a=25
b=7

; result will be 3
Debug a / b
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
Post Reply