Absolute Val for Integers?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Absolute Val for Integers?

Post by Michael Vogel »

Didn't want to start an 'endless' discussion 'bout that, sorry...
...just thought, the compiler should also avoid 'endless' in it's error message :wink:
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Absolute Val for Integers?

Post by Demivec »

Here's my version also just for the confusion of it :) :

Code: Select all

Macro mMin(a, b)
  (a) * Bool((a) And (((a) <= (b)) Or ((b) = 0))) + (b) * Bool((b) And (((b) < (a)) Or ((a) = 0)))
EndMacro

s.s = ""
Debug "m |-3 -2 -1 0  1  2  3"
Debug "--+--------------------"
For a = -3 To 3
   s = "" + RSet(Str(a), 2, " ") + "|"
   For b = -3 To 3
      m = mMin(a, b)
      s + RSet(Str(m), 2, " ") + " "
   Next b
   Debug s
Next a
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Absolute Val for Integers?

Post by #NULL »

In some cases the compiler can't evaluate the macro arguments first, because they might make sense only in combination with other macro content like concatenation with # inside the macro body. Avoiding the recursion error if caused by an argument may work but then actual endless recursion might be possible again.
Post Reply