1 /* ISC license. */
2 
3 #include <errno.h>
4 #include <skalibs/biguint.h>
5 
bu_div(uint32_t const * a,unsigned int an,uint32_t const * b,unsigned int bn,uint32_t * q,unsigned int qn,uint32_t * r,unsigned int rn)6 int bu_div (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn, uint32_t *r, unsigned int rn)
7 {
8   unsigned int alen = bu_len(a, an) ;
9   unsigned int blen = bu_len(b, bn) ;
10   if (!blen) return (errno = EDOM, 0) ;
11   else
12   {
13     uint32_t qq[alen] ;
14     uint32_t rr[alen] ;
15     int qh, rh ;
16     bu_copy_internal(rr, a, alen) ;
17     bu_div_internal(rr, alen, b, blen, qq, alen) ;
18     qh = bu_copy(q, qn, qq, alen) ;
19     rh = bu_copy(r, rn, rr, alen) ;
20     return qh && rh ;
21   }
22 }
23