decabs() — Decimal absolute value

Standards

Standards / Extensions C or C++ Dependencies
C Library C only  

Format

#include <decimal.h>

decimal(n,p) decabs(decimal(n,p) pdec);

General description

The built-in function decabs() accepts a decimal type expression as an argument and returns the absolute value of the decimal argument, in the same decimal type as the argument. The function does not change the content of the argument.

The parameter n can be any integral value between 1 and DEC_DIG. The parameter p can be any integral value between 0 and DEC_PRECISION, although it must be less than or equal to n. DEC_DIG and DEC_PRECISION are defined inside decimal.h.

If the content of the given argument is not in native packed decimal format, behavior is undefined.

Example

CELEBD01
⁄* CELEBD01 *⁄
#include <decimal.h>

decimal(10,2) p1, p2;
int main(void) {
    p2 = -1234.56d;
    p1 = decabs(p2);
    printf("p1 = %D(10,2), p2 = %D(10,2)\n", p1, p2);
    return(0);
}
Output
p1 = 1234.56, p2 = -1234.56

Related information