Modulo Function

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by pusztry.

Is there a built in Modulo function for PB?
If there is not is there another way to get at the remainder of division?(the long way)
Ex:
5%10 or 5 mod 10


Ryan

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

If you don't want to do the math... you could do it the easy way by using IMod() found in the MathExtra ASM Library. (get it from the Resources Site)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by pusztry.
Originally posted by Paul

If you don't want to do the math... you could do it the easy way by using IMod() found in the MathExtra ASM Library. (get it from the Resources Site)
What is the math?:evil:

Ryan

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Something like this...

Code: Select all

Procedure.l Mod(value.l,divisor.l)
  v1=value/divisor
  v2=v1*divisor
  result=value-v2  
  ProcedureReturn result
EndProcedure
 
MessageRequester("",Str(Mod(14,4)),0)
So the MOD of 14/4 will return 2...
4 goes into 14 three times with a remainder of 2 :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Thats what i use:

Code: Select all

Procedure.l MOD(a,b)
  ProcedureReturn a-a/b*b
EndProcedure
:)

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

LOL... Danilo makes my code look bloated :)

Oh well, we'll say I was trying to break it down to show what's going on... hehe :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

...

Funny ... I was using

Procedure.l IMod(a.l, b.l)
ProcedureReturn a - (b * (a / b))
EndProcedure

until now but will change with Danilo's to save 2 assembler steps !

Have a nice day.

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
Originally posted by fweil

...
until now but will change with Danilo's to save 2 assembler steps !
As long a future release of PureBasic does the math in the correct order without parenthesis... :)

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by pusztry.

That helps.
Thanks

Ryan

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra
Post Reply