mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Global: Avoid floating-point equality checks where possible
This commit is contained in:
parent
081b1ff216
commit
28414a6af8
150 changed files with 762 additions and 672 deletions
|
|
@ -271,7 +271,7 @@ private:
|
|||
auto value1 = bufferData.getSample (channel, index1);
|
||||
auto value2 = bufferData.getSample (channel, index2);
|
||||
|
||||
auto output = delayFrac == 0 ? value1 : value2 + alpha * (value1 - v[(size_t) channel]);
|
||||
auto output = approximatelyEqual (delayFrac, (SampleType) 0) ? value1 : value2 + alpha * (value1 - v[(size_t) channel]);
|
||||
v[(size_t) channel] = output;
|
||||
|
||||
return output;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@ Coefficients<NumericType>& Coefficients<NumericType>::assignImpl (const NumericT
|
|||
static_assert (Num % 2 == 0, "Must supply an even number of coefficients");
|
||||
const auto a0Index = Num / 2;
|
||||
const auto a0 = values[a0Index];
|
||||
const auto a0Inv = a0 != NumericType() ? static_cast<NumericType> (1) / values[a0Index]
|
||||
: NumericType();
|
||||
const auto a0Inv = ! approximatelyEqual (a0, NumericType())
|
||||
? static_cast<NumericType> (1) / values[a0Index]
|
||||
: NumericType();
|
||||
|
||||
coefficients.clearQuick();
|
||||
coefficients.ensureStorageAllocated ((int) jmax ((size_t) 8, Num));
|
||||
|
|
|
|||
|
|
@ -755,7 +755,7 @@ void Oversampling<SampleType>::updateDelayLine()
|
|||
auto latency = getUncompensatedLatency();
|
||||
fractionalDelay = static_cast<SampleType> (1.0) - (latency - std::floor (latency));
|
||||
|
||||
if (fractionalDelay == static_cast<SampleType> (1.0))
|
||||
if (approximatelyEqual (fractionalDelay, static_cast<SampleType> (1.0)))
|
||||
fractionalDelay = static_cast<SampleType> (0.0);
|
||||
else if (fractionalDelay < static_cast<SampleType> (0.618))
|
||||
fractionalDelay += static_cast<SampleType> (1.0);
|
||||
|
|
|
|||
|
|
@ -48,9 +48,12 @@ struct ProcessSpec
|
|||
|
||||
constexpr bool operator== (const ProcessSpec& a, const ProcessSpec& b)
|
||||
{
|
||||
return a.sampleRate == b.sampleRate
|
||||
&& a.maximumBlockSize == b.maximumBlockSize
|
||||
&& a.numChannels == b.numChannels;
|
||||
const auto tie = [] (const ProcessSpec& p)
|
||||
{
|
||||
return std::tie (p.sampleRate, p.maximumBlockSize, p.numChannels);
|
||||
};
|
||||
|
||||
return tie (a) == tie (b);
|
||||
}
|
||||
|
||||
constexpr bool operator!= (const ProcessSpec& a, const ProcessSpec& b) { return ! (a == b); }
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ProcessorChainTest : public UnitTest
|
|||
template <typename Context>
|
||||
void process (const Context& context) noexcept
|
||||
{
|
||||
bufferWasClear = context.getInputBlock().getSample (0, 0) == 0;
|
||||
bufferWasClear = approximatelyEqual (context.getInputBlock().getSample (0, 0), 0.0f);
|
||||
|
||||
if (! context.isBypassed)
|
||||
context.getOutputBlock().add (AddValue);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue