80 if (b == 0)
return a < 0 ? INT32_MIN : INT32_MAX;
85 int64_t c = ((int64_t) a) << 30U;
86 if ((uint32_t) (a ^ b) & 0x80000000U)
88 c = (((-c) / b) + (1 << 13U)) >> 14U;
89 if (c > 0x80000000U)
return INT32_MIN;
94 c = ((c / b) + (1 << 13U)) >> 14U;
95 if (c > (int64_t)INT32_MAX)
return INT32_MAX;
107 uint32_t remainder =
absval(a);
108 uint32_t divider =
absval(b);
110 uint32_t quotient = 0;
111 uint32_t bit = 0x10000U;
114 while (divider < remainder)
122 if ((uint32_t)(a ^ b) & 0x80000000U)
132 if (divider & 0x80000000U)
136 if (remainder >= divider)
139 remainder -= divider;
146 while (bit && remainder)
148 if (remainder >= divider)
151 remainder -= divider;
157 if (remainder >= divider)
162 uint32_t result = quotient;
165 if ((uint32_t)(a ^ b) & 0x80000000U)
167 return (int32_t)-result;
173 if (quotient > INT32_MAX)
return INT32_MAX;
174 return (int32_t)result;
This file is part of the AFBR-S50 API.
int32_t fp_div16(int32_t a, q15_16_t b)
32-bit implementation of an Q15.16 division.
Definition fp_div.h:77
int32_t q15_16_t
Signed fixed point number: Q15.16.
Definition fp_def.h:515
uint32_t absval(int32_t x)
Calculates the absolute value.
Definition int_math.h:155
This file is part of the AFBR-S50 API.