Skip to content

Commit

Permalink
Fix potential floating point equality issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDesmond-ca committed Nov 28, 2024
1 parent 33c897a commit f5221b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions SimpleGPIO.Tests/Components/RGBLEDTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ private sealed class ColorData : IEnumerable<object[]>

public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { Color.Red, 100, 0, 0 };
yield return new object[] { Color.Yellow, 100, 100, 0 };
yield return new object[] { Color.Lime, 0, 100, 0 };
yield return new object[] { Color.Cyan, 0, 100, 100 };
yield return new object[] { Color.Blue, 0, 0, 100 };
yield return new object[] { Color.Magenta, 100, 0, 100 };
yield return new object[] { Color.White, 100, 100, 100 };
yield return new object[] { Color.Black, 0, 0, 0 };
yield return [Color.Red, 100, 0, 0];
yield return [Color.Yellow, 100, 100, 0];
yield return [Color.Lime, 0, 100, 0];
yield return [Color.Cyan, 0, 100, 100];
yield return [Color.Blue, 0, 0, 100];
yield return [Color.Magenta, 100, 0, 100];
yield return [Color.White, 100, 100, 100];
yield return [Color.Black, 0, 0, 0];
}
}
}
4 changes: 2 additions & 2 deletions SimpleGPIO/GPIO/PinInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public double Strength
{
_strength = value.Clamp(0, 100);

if (Power == PowerValue.On && _strength == 0)
if (Power == PowerValue.On && System.Math.Abs(_strength) < double.Epsilon)
{
TurnOff();
}

RefreshPWM();

if (Power != PowerValue.On && _strength > 0)
if (Power != PowerValue.On && _strength > double.Epsilon)
{
TurnOn();
}
Expand Down
2 changes: 1 addition & 1 deletion SimpleGPIO/SimpleGPIO.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<LangVersion>latest</LangVersion>
Expand Down

0 comments on commit f5221b5

Please sign in to comment.