1
0
Fork 0
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:
reuk 2023-03-23 12:02:38 +00:00
parent 081b1ff216
commit 28414a6af8
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
150 changed files with 762 additions and 672 deletions

View file

@ -188,7 +188,7 @@ public:
if (canMoveTransport())
setRange ({ newStart, newStart + visibleRange.getLength() });
if (wheel.deltaY != 0.0f)
if (! approximatelyEqual (wheel.deltaY, 0.0f))
zoomSlider.setValue (zoomSlider.getValue() - wheel.deltaY);
repaint();

View file

@ -88,8 +88,8 @@ struct SineWaveVoice : public SynthesiserVoice
// start a tail-off by setting this flag. The render callback will pick up on
// this and do a fade out, calling clearCurrentNote() when it's finished.
if (tailOff == 0.0) // we only need to begin a tail-off if it's not already doing so - the
tailOff = 1.0; // stopNote method could be called more than once.
if (approximatelyEqual (tailOff, 0.0)) // we only need to begin a tail-off if it's not already doing so - the
tailOff = 1.0; // stopNote method could be called more than once.
}
else
{
@ -104,7 +104,7 @@ struct SineWaveVoice : public SynthesiserVoice
void renderNextBlock (AudioBuffer<float>& outputBuffer, int startSample, int numSamples) override
{
if (angleDelta != 0.0)
if (! approximatelyEqual (angleDelta, 0.0))
{
if (tailOff > 0.0)
{

View file

@ -499,8 +499,8 @@ public:
// start a tail-off by setting this flag. The render callback will pick up on
// this and do a fade out, calling clearCurrentNote() when it's finished.
if (tailOff == 0.0) // we only need to begin a tail-off if it's not already doing so - the
// stopNote method could be called more than once.
if (approximatelyEqual (tailOff, 0.0)) // we only need to begin a tail-off if it's not already doing so - the
// stopNote method could be called more than once.
tailOff = 1.0;
}
else
@ -530,7 +530,7 @@ public:
void setCurrentSampleRate (double newRate) override
{
if (currentSampleRate != newRate)
if (! approximatelyEqual (currentSampleRate, newRate))
{
noteStopped (false);
currentSampleRate = newRate;
@ -546,7 +546,7 @@ public:
int startSample,
int numSamples) override
{
if (phaseDelta != 0.0)
if (! approximatelyEqual (phaseDelta, 0.0))
{
if (tailOff > 0.0)
{

View file

@ -77,7 +77,7 @@ struct FIRFilterDemoDSP
void updateParameters()
{
if (sampleRate != 0.0)
if (! approximatelyEqual (sampleRate, 0.0))
{
auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
auto windowingMethod = static_cast<WindowingFunction<float>::WindowingMethod> (typeParam.getCurrentSelectedID() - 1);

View file

@ -76,7 +76,7 @@ struct IIRFilterDemoDSP
void updateParameters()
{
if (sampleRate != 0.0)
if (! approximatelyEqual (sampleRate, 0.0))
{
auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
auto qVal = static_cast<float> (qParam.getCurrentValue());

View file

@ -90,7 +90,7 @@ struct OverdriveDemoDSP
void updateParameters()
{
if (sampleRate != 0.0)
if (! approximatelyEqual (sampleRate, 0.0))
{
overdrive.get<0>().setGainDecibels (static_cast<float> (inGainParam.getCurrentValue()));
overdrive.get<4>().setGainDecibels (static_cast<float> (outGainParam.getCurrentValue()));

View file

@ -124,7 +124,7 @@ struct SIMDRegisterDemoDSP
void updateParameters()
{
if (sampleRate != 0.0)
if (! approximatelyEqual (sampleRate, 0.0))
{
auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
auto qVal = static_cast<float> (qParam.getCurrentValue());

View file

@ -74,7 +74,7 @@ struct StateVariableFilterDemoDSP
void updateParameters()
{
if (sampleRate != 0.0)
if (! approximatelyEqual (sampleRate, 0.0))
{
filter.setCutoffFrequency (static_cast<float> (cutoffParam.getCurrentValue()));
filter.setResonance (static_cast<float> (qParam.getCurrentValue()));

View file

@ -630,7 +630,7 @@ private:
currentPositionLabel.setText (getPositionString (position, duration), sendNotification);
if (! positionSliderDragging)
positionSlider.setValue (duration != 0 ? (position / duration) : 0.0, dontSendNotification);
positionSlider.setValue (approximatelyEqual (duration, 0.0) ? 0.0 : (position / duration), dontSendNotification);
}
void seekVideoToStart()

View file

@ -97,8 +97,8 @@ public:
// start a tail-off by setting this flag. The render callback will pick up on
// this and do a fade out, calling clearCurrentNote() when it's finished.
if (tailOff == 0.0) // we only need to begin a tail-off if it's not already doing so - the
// stopNote method could be called more than once.
if (approximatelyEqual (tailOff, 0.0)) // we only need to begin a tail-off if it's not already doing so - the
// stopNote method could be called more than once.
tailOff = 1.0;
}
else
@ -122,7 +122,7 @@ public:
void renderNextBlock (AudioBuffer<float>& outputBuffer, int startSample, int numSamples) override
{
if (angleDelta != 0.0)
if (! approximatelyEqual (angleDelta, 0.0))
{
if (tailOff > 0.0)
{

View file

@ -969,7 +969,7 @@ private:
//==============================================================================
static String getPanningTextForValue (float value)
{
if (value == 0.5f)
if (approximatelyEqual (value, 0.5f))
return "center";
if (value < 0.5f)

View file

@ -291,7 +291,7 @@ public:
{
jassert (currentlyPlayingNote.keyState == MPENote::off);
if (allowTailOff && tailOff == 0.0)
if (allowTailOff && approximatelyEqual (tailOff, 0.0))
tailOff = 1.0;
else
stopNote();
@ -422,7 +422,7 @@ private:
bool isTailingOff() const
{
return tailOff != 0.0;
return ! approximatelyEqual (tailOff, 0.0);
}
void stopNote()