The ifx_int8add() function
The ifx_int8add() function adds two int8 type values.
Syntax
mint ifx_int8add(n1, n2, sum)
ifx_int8_t *n1;
ifx_int8_t *n2;
ifx_int8_t *sum;
- n1
- A pointer to the int8 structure that contains the first operand.
- n2
- A pointer to the int8 structure that contains the second operand.
- sum
- A pointer to the int8 structure that contains the sum of n1 + n2.
Usage
The sum can be the same as either n1 or n2.
Return codes
- 0
- The operation was successful.
- -1284
- The operation resulted in overflow or underflow.
Example
The file int8add.ec in
the demo directory contains the following sample
program.
*int8add.ec *
The following program obtains the sum of two INT8 type values.
*/
#include <stdio.h>
EXEC SQL include "int8.h";
char string1[] = "6";
char string2[] = "9,223,372,036,854,775";
char string3[] = "999,999,999,999,999,9995";
char result[41];
main()
{
mint x;
ifx_int8_t num1, num2, num3, sum;
printf("INT8 Sample ESQL Program running.\n\n");
if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8add(&num1, &num2, &sum)) /* adding the first two INT8s */
{
printf("Error %d in adding INT8s\n", x);
exit(1);
}
if (x = ifx_int8toasc(&sum, result, sizeof(result)))
{
printf("Error %d in converting INT8 result to string\n", x);
exit(1);
}
result[40] = '\0';
printf("\t%s + %s = %s\n", string1, string2, result); /* display result */
/* attempt to convert to INT8 value that is too large*/
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{
printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}
if (x = ifx_int8add(&num2, &num3, &sum))
{
printf("Error %d in adding INT8s\n", x);
exit (1);
}
if (x = ifx_int8toasc(&sum, result, sizeof(result)))
{
printf("Error %d in converting INT8 result to string\n", x);
exit(1);
}
result[40] = '\0';
printf("\t%s + %s = %s\n", string2, string3, result); /* display result */
printf("\nINT8 Sample Program over.\n\n");
exit(0);
}
Output
INT8 Sample ESQL Program running.
6 + 9,223,372,036,854,775 = 9223372036854781
Error -1284 in converting string3 to INT8