What is "Mod" in PB? *solved*

Just starting out? Need help? Post your questions and find answers here.
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

What is "Mod" in PB? *solved*

Post by CadeX »

http://www.microsoft.com/technet/script ... y1019.mspx

As described in there (no, i am not Jo) i'm trying to work with odd and even numbers. If anyone knows another alternative, do tell!

Thanks for reading.
Last edited by CadeX on Fri Mar 02, 2007 9:51 am, edited 1 time in total.
Pro-Gamer, Programmer, Pro-Grammer
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Code: Select all

NumberToTest.l = 15
NumberToTest % 2
% = Mod (Modulo)

http://www.purearea.net/pb/english/manu ... ables.html
scroll to the bottom.
Last edited by Kale on Fri Mar 02, 2007 9:51 am, edited 2 times in total.
--Kale

Image
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post by CadeX »

Thankyou very much!
Pro-Gamer, Programmer, Pro-Grammer
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: What is "Mod" in PB? *solved*

Post by PB »

Use % where you see Mod in other Basics. So, for the URL you quoted, do this:

Code: Select all

a = 13

intResult = a % 2

If intResult = 0
    Debug "This is an even number."
ElseIf intResult = 1
    Debug "This is an odd number."
Else
    Debug "This does not appear to be a whole number."
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

hint:

% is quite slow.
since this all is about Integers, you can also test bit 0 to determine odd or even:

Code: Select all

Odd = Value & 1
Demo:

Code: Select all

For attepts = 1 To 100
  Value = Random(999999999)-500000000
; ****  
  Odd = Value & 1
; ****  
  If Odd
    Gen$ = "odd"
  Else
    Gen$ = "even"
  EndIf
  Debug Str(Value) +" is "+Gen$
Next
oh... and have a nice day.
Post Reply