SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL663854-005
3-29
Numeric Data
low-level library routines, mpz_import(). The following example shows the usage of
mpz_import()function:
// Convert the str which has the value "12345678901234567890"
from internal format to GMP.
//Declare the Bignum host variable
NUMERIC(50,5) s;
//Get the storageLength for the NUMERIC s
unsigned short storageLength =SQL_BignumSize(50);
//First, convert the str "12345678901234567890' to Internal
format
SQL_BignumFromStr(s, storageLength , str,
(unsignedshort)strlen(str));
//Declare the Bignum in GMP format
mpz_t z;
// Convert the Internal format s to GMP format z
mpz_import(z, // Output multi-precision in GMP format.
5, // Number of chunks in s.
-1, // Least significant chunk first.
2, // Size of each chunk, in bytes.
0, // Native endianness within the chunk.
0, // Nails.
s // Input Bignum in internal format.
);