Search                        Top                                  Index
HELP SIGN                               Steven Hardy, January 1978

    sign(<number>) -> <1, -1, 0, 1.0, -1.0 or 0.0>

This procedure returns -1 if applied to a negative number, 0 if applied
to 0 and +1 if applied to a positive number. If it is applied to a
decimal number, the sign is marked to one decimal place. It could be
defined as:

    define sign(num);
        if isdecimal(num)
        then
            if num < 0 then -1.0
            elseif num = 0 then 0.0
            else 1.0
            endif
        else
            if num < 0 then -1
            elseif num = 0 then 0
            else 1
            endif;
        endif
    enddefine;

Thus

    sign(x) * x

will always be positive (provided X is a number).

See also:

    REF *NUMBERS    - for details of numbers and mathematical operations
                        available in POP-11.
    HELP *MATH      - for a summary of mathematical operations in POP-11

--- C.all/help/sign ----------------------------------------------------
--- Copyright University of Sussex 1987. All rights reserved. ----------