FastLED 3.9.15
Loading...
Searching...
No Matches
fl::test::Approx Class Reference

Detailed Description

Helper class for approximate floating-point comparisons.

Supports both relative (epsilon) and absolute (margin) tolerance.

Usage: FL_CHECK(value == fl::test::Approx(expected)); FL_CHECK(value == fl::test::Approx(expected).epsilon(0.01)); // 1% relative FL_CHECK(value == fl::test::Approx(expected).margin(0.001)); // absolute margin

Comparison formula: |actual - expected| <= margin OR |actual - expected| <= epsilon * (scale + max(|actual|, |expected|))

By default: epsilon=1e-5, margin=0.0 (only epsilon comparison)

Definition at line 396 of file fltest.h.

#include <fltest.h>

Public Member Functions

 Approx (double value) FL_NOEXCEPT
 
Approxepsilon (double newEpsilon) FL_NOEXCEPT
 Set custom relative epsilon for comparison Comparison uses: epsilon * (scale + max(|a|, |b|))
 
double getEpsilon () const FL_NOEXCEPT
 
double getMargin () const FL_NOEXCEPT
 
double getScale () const FL_NOEXCEPT
 
Approxmargin (double newMargin) FL_NOEXCEPT
 Set absolute margin for comparison When margin > 0, passes if |a - b| <= margin.
 
Approxscale (double newScale) FL_NOEXCEPT
 Set custom scale for comparison.
 
double value () const FL_NOEXCEPT
 

Private Attributes

double mEpsilon
 
double mMargin
 
double mScale
 
double mValue
 

Friends

bool operator!= (const Approx &lhs, double rhs) FL_NOEXCEPT
 
bool operator!= (double lhs, const Approx &rhs) FL_NOEXCEPT
 
bool operator< (double lhs, const Approx &rhs) FL_NOEXCEPT
 
bool operator<= (double lhs, const Approx &rhs) FL_NOEXCEPT
 
bool operator== (const Approx &lhs, double rhs) FL_NOEXCEPT
 
bool operator== (double lhs, const Approx &rhs) FL_NOEXCEPT
 
bool operator> (double lhs, const Approx &rhs) FL_NOEXCEPT
 
bool operator>= (double lhs, const Approx &rhs) FL_NOEXCEPT
 

The documentation for this class was generated from the following file: