The invdivdbl() function
The invdivdbl() function divides an interval value by a numeric value.
Syntax
mint invdivdbl(iv, num, ov)
intrvl_t *iv;
double num;
intrvl_t *ov;
- iv
- A pointer to an interval variable to be divided.
- num
- A numeric divisor value.
- ov
- A pointer to an interval variable with a valid qualifier.
Usage
The input and output qualifiers must both belong to the same interval class: either the year to month class or the day to fraction(5) class. If the qualifier for ov is different from the qualifier for iv (within the same class), the invdivdbl() function extends the result (as the invextend() function defines).
The invdivdbl() function divides the interval value in iv by num and stores the result in ov.
The value in num can be either a positive or a negative value.
Return codes
- 0
- The division was successful.
- <0
- The division failed.
- -1200
- A numeric value is too large (in magnitude).
- -1201
- A numeric value is too small (in magnitude).
- -1202
- The num parameter is zero (0).
- -1265
- Overflow occurred on an interval operation.
- -1266
- An interval value is incompatible with the operation.
- -1268
- A parameter contains an invalid interval qualifier.
Example
/*
* indivdbl.ec *
The following program divides an INTERVAL type variable by a numeric
value and stores the result in an INTERVAL variable. The operation is
done twice, using INTERVALs with different qualifiers to store the result.
*/
#include <stdio.h>
EXEC SQL include datetime;
main()
{
char out_str[16];
EXEC SQL BEGIN DECLARE SECTION;
interval day to second daytosec1;
interval hour to minute hrtomin;
interval day to second daytosec2;
EXEC SQL END DECLARE SECTION;
printf("INVDIVDBL Sample ESQL Program running.\n\n");
/* Input is 3 days, 5 hours, 27 minutes, and 30 seconds */
printf("Interval (day to second) string = '3 5:27:30'\n");
incvasc("3 5:27:30", &daytosec1);
/* Divide input value by 3.0, store in hour to min interval */
invdivdbl(&daytosec1, (double) 3.0, &hrtomin);
/* Convert the internal format to ascii for displaying */
intoasc(&hrtomin, out_str);
printf("Divisor (double) = 3.0 \n");
printf("-----------------------------------------------------\n");
printf("Quotient #1 (hour to minute) = '%s'\n", out_str);
/* Divide input value by 3.0, store in day to sec interval variable */
invdivdbl(&hrtomin, (double) 3.0, &daytosec2);
/* Convert the internal format to ascii for displaying */
intoasc(&daytosec2, out_str);
printf("Quotient #2 (day to second) = '%s'\n", out_str);
printf("\nINVDIVDBL Sample Program over.\n\n");
}
Output
INVDIVDBL Sample ESQL Program running.
Interval (day to second) string = '3 5:27:30'
Divisor (double) = 3.0
---------------------------------------------
Quotient #1 (hour to minute) = ' 25:49'
Quotient #2 (day to second) = ' 1 01:49:10'
INVDIVDBL Sample Program over.