FastLED 3.10.6
Loading...
Searching...
No Matches

◆ narrowTotalForPair()

bool fl::anonymous_namespace{white_allocation.cpp.hpp}::narrowTotalForPair ( const SplitBound & lower,
const SplitBound & upper,
i64 * low,
i64 * high )

The totals at which lower <= upper holds, narrowed into [*low, *high].

Returns false when the pair excludes every total, which is the one case the caller cannot express as a narrowed interval.

Cross-multiplied rather than divided first: with positive denominators the inequality

(nL + mL*s) / qL  <=  (nU + mU*s) / qU

is s * (qU*mL - qL*mU) <= qL*nU - qU*nL, one linear inequality in s whose coefficients are exact in i64.

Definition at line 332 of file white_allocation.cpp.hpp.

333 {
334 const i64 slope = static_cast<i64>(upper.denominator) * lower.slope -
335 static_cast<i64>(lower.denominator) * upper.slope;
336 const i64 constant = static_cast<i64>(lower.denominator) * upper.numerator -
337 static_cast<i64>(upper.denominator) * lower.numerator;
338 if (slope == 0) {
339 // No s makes this pair better or worse; it either always holds or
340 // never does.
341 return constant >= 0;
342 }
343 const i64 bound = (constant * 65536) / slope;
344 if (slope > 0) {
345 if (bound < *high) {
346 *high = bound;
347 }
348 } else if (bound > *low) {
349 *low = bound;
350 }
351 return true;
352}
fl::i64 i64
Definition stdint.h:221

References fl::FL_NO_EXCEPT, and narrowTotalForPair().

Referenced by narrowTotalForPair().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: