Max() and Min(), procedure and macro variants.

Share your advanced PureBasic knowledge/code with the community.
pjay
Enthusiast
Enthusiast
Posts: 251
Joined: Thu Mar 30, 2006 11:14 am

Re: Max() and Min(), procedure and macro variants.

Post by pjay »

The macro won't do the job here as it'll return 0 for a 255 input, I think you need: '(Bool(a <= 255) ...'
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: Max() and Min(), procedure and macro variants.

Post by Mijikai »

Playing around:

Code: Select all

EnableExplicit

Macro min(_a_,_b_,_c_)
  !((v_#_a_) < (v_#_b_) ? (v_#_c_ = v_#_a_) : (v_#_c_ = v_#_b_));
EndMacro

Macro max(_a_,_b_,_c_)
  !((v_#_a_) > (v_#_b_) ? (v_#_c_ = v_#_a_) : (v_#_c_ = v_#_b_));
EndMacro

Procedure.i main()
  Protected.i a,b,c
  a = 1
  b = 2
  min(a,b,c)
  Debug c
  max(a,b,c)
  Debug c
  ProcedureReturn #Null
EndProcedure

End main()
Post Reply