Flutter Impeller
impeller::saturated Namespace Reference

Functions

 ONLY_ON_SIGNED_INT (SI) Add(SI location
 
 ONLY_ON_FLOAT (FP) Add(FP location
 
 ONLY_ON_SIGNED_INT_RET (SI, Scalar) AverageScalar(SI a
 
 ONLY_ON_SAME_TYPES (T, U) Cast(T v)
 
 ONLY_ON_FLOAT_TO_SIGNED_INT (FP, SI) Cast(FP v)
 
 ONLY_ON_DIFFERING_FLOAT (FP1, FP2) Cast(FP1 v)
 

Variables

template<typename T >
constexpr bool is_signed_integral_v
 
SI distance
 
SI lower
 
SI b
 

Function Documentation

◆ ONLY_ON_DIFFERING_FLOAT()

impeller::saturated::ONLY_ON_DIFFERING_FLOAT ( FP1  ,
FP2   
)

Definition at line 122 of file saturated_math.h.

122  {
123  if (std::isfinite(v)) {
124  // Avoid truncation to inf/-inf.
125  return std::clamp(static_cast<FP2>(v), //
126  std::numeric_limits<FP2>::lowest(),
127  std::numeric_limits<FP2>::max());
128  } else {
129  return static_cast<FP2>(v);
130  }
131 }

◆ ONLY_ON_FLOAT()

impeller::saturated::ONLY_ON_FLOAT ( FP  )

References distance.

◆ ONLY_ON_FLOAT_TO_SIGNED_INT()

impeller::saturated::ONLY_ON_FLOAT_TO_SIGNED_INT ( FP  ,
SI   
)

Definition at line 113 of file saturated_math.h.

113  {
114  if (v <= static_cast<FP>(std::numeric_limits<SI>::min())) {
115  return std::numeric_limits<SI>::min();
116  } else if (v >= static_cast<FP>(std::numeric_limits<SI>::max())) {
117  return std::numeric_limits<SI>::max();
118  }
119  return static_cast<SI>(v);
120 }

◆ ONLY_ON_SAME_TYPES()

impeller::saturated::ONLY_ON_SAME_TYPES ( ,
 
)

Definition at line 109 of file saturated_math.h.

109  {
110  return v;
111 }

◆ ONLY_ON_SIGNED_INT()

impeller::saturated::ONLY_ON_SIGNED_INT ( SI  )

◆ ONLY_ON_SIGNED_INT_RET()

impeller::saturated::ONLY_ON_SIGNED_INT_RET ( SI  ,
Scalar   
)

Variable Documentation

◆ b

◆ distance

FP impeller::saturated::distance
Initial value:
{
if (location >= 0) {
if (distance > std::numeric_limits<SI>::max() - location) {
return std::numeric_limits<SI>::max();
}
} else if (distance < std::numeric_limits<SI>::min() - location) {
return std::numeric_limits<SI>::min();
}
return location + distance

Definition at line 57 of file saturated_math.h.

Referenced by ONLY_ON_FLOAT(), and impeller::testing::TEST_P().

◆ is_signed_integral_v

template<typename T >
constexpr bool impeller::saturated::is_signed_integral_v
inlineconstexpr
Initial value:
=
std::is_integral_v<T> && std::is_signed_v<T>

Definition at line 21 of file saturated_math.h.

◆ lower

FP impeller::saturated::lower
Initial value:
{
if (upper >= 0) {
if (lower < 0 && upper > std::numeric_limits<SI>::max() + lower) {
return std::numeric_limits<SI>::max();
}
} else if (lower > 0 && upper < std::numeric_limits<SI>::min() + lower) {
return std::numeric_limits<SI>::min();
}
return upper - lower

Definition at line 72 of file saturated_math.h.