On 2013-10-24 09:35, David Cole wrote:
>
> The reason that this useful is that this quirk can be exploited to
> create, for example, a MAX or MIN function that is evaluated at
> assembly time. (Maybe this has changed, but the last time I looked,
> the Assembler did not offer native MAX and MIN functions.)
>
Are you confident that was the motivation for the behavior?
I suppose it's possible.

>     ...
> I'll translate this into something more readable:
>     (A/B)/(A/B)*A
>
> Here's a better layout (better when your font is courier):
>     A/B
>     --- * A
>     A/B
>
I recognize from the comments that you had a specialized
requirement and were not trying to provide a general purpose
MAX function.  Regardless, I believe I spot the restrictions
(by inspection, not tested):

o I believe this gives MAX(-5,+3)=-5, not the +3 I'd expect.

o I believe MAX(-2147483648,-1) results in an integer overflow
  error, ASMA057E.

(Should I see the source of your macro somewhere, or is it
proprietary?)

Here's my attempt at it.  It has a more symmetric, although
(much) more restricted but still useful argument domain.  It
does not depend on division by zero -- tested by translating
to Rexx which treats division by zero as a error.  Test code
attached:

* MAX function through the marvel of integer arithmetic.  Valid for
* arguments in the range [-357913940,357913940].  Arguments outside
* that range will either give correct results or report overflow
* with ASMA075E.  Division by zero does not occur.
*
         MACRO
&L       MAX   &X,&Y
L&SYSNDX DC    A(((((&X)-(&Y))*3)/(((&X)-(&Y))*3+1))*(&Y)+(-3+((&Y)-(&X,
               ))*3)/(-2+((&Y)-(&X))*3)*(&X))
         MEND
*
TINY     CSECT
         MAX   +5,+3
         MAX   -5,+3
         MAX   +5,-3
         MAX   -5,-3
         MAX   08,11
         MAX   09,11
         MAX   10,11
         MAX   11,11
         MAX   12,11
         MAX   13,11
         MAX   14,11
         MAX   357913940,-357913940
         MAX   -357913940,357913940
         MAX   999999999,999999999
         MAX   357913941,-357913941
         MAX   357913942,-357913942
         END

Coefficients chosen empirically.  I believe that with much more
Diophantine gymnastics I could make it work for all integer values.
I'm not much motivated.

-- gil

Reply via email to