decfix() — Fix up a nonpreferred sign variable

Standards

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

Format

#include <decimal.h>

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

General description

The built-in function decfix() accepts a decimal type expression as an argument and returns a decimal value that has the same type and same value as the argument with the correct preferred sign. 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, though 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

#include <decimal.h>

char *ptr;
char mem[3] = { 0x01, 0x23, 0x4A };
decimal(4,0) *pp;
decimal(4,0) p;
int main(void) {
    pp = (decimal(4,0) *) mem;
    p = decfix(*pp);
    ptr = (char *) p;
    printf("Before decfix : %X%X%X\n", mem[0], mem[1], mem[2]);
    printf("After  decfix : %X%X%X\n", ptr[0], ptr[1], ptr[2]);
    return(0);
}
Output
Before decfix : 1234A
After  decfix : 1234C

Related information