FastLED 3.9.15
Loading...
Searching...
No Matches

◆ avg8()

LIB8STATIC_ALWAYS_INLINE uint8_t avg8 ( uint8_t i,
uint8_t j )

Calculate an integer average of two unsigned 8-bit integer values (uint8_t), rounded down.

Fractional results are rounded down, e.g. avg8(20,41) = 30

Parameters
ifirst value to average
jsecond value to average
Returns
mean average of i and j, rounded down

Definition at line 202 of file math8.h.

202 {
203#if AVG8_C == 1
204 return (i + j) >> 1;
205#elif AVG8_AVRASM == 1
206 asm volatile(
207 /* First, add j to i, 9th bit overflows into C flag */
208 "add %0, %1 \n\t"
209 /* Divide by two, moving C flag into high 8th bit */
210 "ror %0 \n\t"
211 : "+r"(i)
212 : "r"(j));
213 return i;
214#else
215#error "No implementation for avg8 available."
216#endif
217}

References LIB8STATIC_ALWAYS_INLINE.