Little helpers

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Thomas
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Apr 26, 2003 8:45 pm

Little helpers

Post by Thomas »

Functions like Min(x,y), Max(x,y), Odd(x), Even(x), etc. can be realised differently but it would make coding easier.
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Can you explain Odd and Even functions :?: Never seen before...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Blade wrote:Can you explain Odd and Even functions :?: Never seen before...
I also have not seen before that functions, but to get whether an integer is even or odd i use:
If integer.l&1 ; <- if yes, that means it is Odd, else Even
So no needed a function for it :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Thomas
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Apr 26, 2003 8:45 pm

Post by Thomas »

You also can use number%2=0 but the code would be more readable if such functions exist.
MikeB
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Apr 27, 2003 8:39 pm
Location: Cornwall UK

Post by MikeB »

I agree it would be easier to have these commands, but at the moment I just copy the following to the top of my prog.

Code: Select all

Procedure odd(num)
    result=num & 1
    ProcedureReturn result
EndProcedure
;
Procedure EVEN(num)
    result=(num & 1) ! 1
    ProcedureReturn result
EndProcedure
;
Procedure.f maxf(num.f,num2.f)
    If num>num2
        ProcedureReturn num
    Else
        ProcedureReturn num2
    EndIf
EndProcedure
;
Procedure max(num,num2)
    If num>num2
        ProcedureReturn num
    Else
        ProcedureReturn num2
    EndIf
EndProcedure
;
Procedure.f minf(num.f,num2.f)
    If num<num2
        ProcedureReturn num
    Else
        ProcedureReturn num2
    EndIf
EndProcedure
;
Procedure min(num,num2)
    If num<num2
        ProcedureReturn num
    Else
        ProcedureReturn num2
    EndIf
EndProcedure
MikeB
Post Reply