aabbss() -- General Function (libc)

Return the absolute value of an integer
#iinncclluuddee <ssttddlliibb.hh>
iinntt aabbss(_n) iinntt _n;

aabbss() returns  the absolute value  of integer _n.   The _a_b_s_o_l_u_t_e _v_a_l_u_e  of a
number is its distance from zero.  This is _n if _n>=00, and -_n otherwise.

_E_x_a_m_p_l_e
This example prompts for a number, and returns its absolute value.

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

main()
{
    extern char *gets();
    extern int atoi();
    char string[64];
    int counter;
    int input;

    printf("Enter an integer: ");
    fflush(stdout);
    gets(string);

    for (counter=0; counter < strlen(string); counter++) {
        input = string[counter];

        if (!isascii(input)) {
            fprintf(stderr,
                "%s is not ASCII\n", string);
            exit(EXIT_FAILURE);
        }

        if (!isdigit(input))
            if (input != '-' || counter != 0) {
                fprintf(stderr,
                    "%s is not a number\n", string);
                exit(1);
            }
    }

    input = atoi(string);
    printf("abs(%d) is %d\n", input, abs(input));
    exit(EXIT_SUCCESS);
}

_S_e_e _A_l_s_o
ffaabbss(), fflloooorr(), iinntt, lliibbcc, ssttddlliibb.hh
ANSI Standard, section 7.10.6.1
POSIX Standard, section 8.1

_N_o_t_e_s
On two's  complement machines,  the aabbss() of  the most negative  integer is
itself.
