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 193 of file math8.h.

193 {
194#if AVG8_C == 1
195 return (i + j) >> 1;
196#elif AVG8_AVRASM == 1
197 asm volatile(
198 /* First, add j to i, 9th bit overflows into C flag */
199 "add %0, %1 \n\t"
200 /* Divide by two, moving C flag into high 8th bit */
201 "ror %0 \n\t"
202 : "+r"(i)
203 : "r"(j));
204 return i;
205#else
206#error "No implementation for avg8 available."
207#endif
208}

References LIB8STATIC_ALWAYS_INLINE.