Add iso8601_elapsed_divide()

This commit is contained in:
Laurence Withers 2009-05-29 14:51:14 +00:00
parent dcfc699af0
commit b7d039a32c
2 changed files with 46 additions and 0 deletions

View File

@ -160,6 +160,31 @@ void iso8601_difference(const struct iso8601_date* d1, const struct iso8601_date
int iso8601_elapsed_div(const struct iso8601_elapsed* num, const struct iso8601_elapsed* denom,
struct iso8601_elapsed* remain)
{
unsigned long long pnum, pdenom;
lldiv_t val, v2;
pnum = num->sec;
pnum *= BILLION;
pnum += num->nsec;
pdenom = denom->sec;
pdenom *= BILLION;
pdenom += denom->nsec;
val = lldiv(pnum, pdenom);
if(remain) {
v2 = lldiv(val.rem, BILLION);
remain->sec = v2.quot;
remain->nsec = v2.rem;
}
return val.quot;
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4

View File

@ -117,6 +117,27 @@ void iso8601_difference(const struct iso8601_date* d1, const struct iso8601_date
/*! \brief Divide one period by another.
\param num Numerator.
\param denom Denominator (divisor).
\param[out] remain Remainder. May be 0.
\returns Number of times \a denom divides into \a num.
This function computes the number of times that \a denom can be divided into \a num, returning that
number. If desired, the remaining period which could not be divided can be written into \a remain.
Uses 64-bit arithmetic internally.
*/
int iso8601_elapsed_div(const struct iso8601_elapsed* num, const struct iso8601_elapsed* denom,
struct iso8601_elapsed* remain)
#ifndef DOXYGEN
__attribute__((nonnull(1,2)));
#endif
;
/*!@}*/
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;