On 2013-10-21 11:06, John Gilmore wrote:
>
> [signum] is available as a BIF called sign in PL/I, where it is [almost 
> always]
> implemented in line.  An analogous function is available for strings
> in C, where it is implemented as a library subroutine.  It has always
> been available in FORTRAN in the form of the much deprecated but in
> fact enormously useful arithmetic-IF statement
>
(They seem to have borrowed the name from FORTRAN.)

One might consider implementing a dyadic signum as:

    #define signum2( a, b ) ( ( ( a ) < ( b ) ) - ( ( a ) > ( b ) ) )

... in any language where TRUE==1 and FALSE==0.  (Is this the case in
PL/I?)

Beware the shortcut:

    #define signum2( a, b ) ( signum( ( b ) - ( a ) ) )

... which misbehaves for extreme values of a and b.

Alas, I know of no C implementation which reports integer overflow
of signed operands, although ANSI tolerates this behavior.  I prefer
to be told of such exceptional conditions.  (Didn't you say that PL/I
lately robbed programmers of that facility?)  I find a few occurrences
of FPE_INTOVF buried in /usr/include.

-- gil

Reply via email to