You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Equals(T other, T maxError), obsolete Equals(T other) for Double quantities
Equality comparison is not safe with System.Double as internal representation.
Decimal quantities (Power, Information) still allow equality.
Add test on new Equals() method.
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1076
1079
publicoverrideboolEquals(objectobj)
1077
1080
{
1078
1081
if(obj==null||GetType()!=obj.GetType())
@@ -1083,6 +1086,19 @@ public override bool Equals(object obj)
Copy file name to clipboardExpand all lines: UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1830,19 +1830,22 @@ int CompareTo(AmountOfSubstance other)
1830
1830
returnleft._moles>right._moles;
1831
1831
}
1832
1832
1833
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
// ReSharper disable once CompareOfFloatsByEqualityOperator
1836
1837
returnleft._moles==right._moles;
1837
1838
}
1838
1839
1840
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
// ReSharper disable once CompareOfFloatsByEqualityOperator
1842
1844
returnleft._moles!=right._moles;
1843
1845
}
1844
1846
#endif
1845
1847
1848
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1846
1849
publicoverrideboolEquals(objectobj)
1847
1850
{
1848
1851
if(obj==null||GetType()!=obj.GetType())
@@ -1853,6 +1856,19 @@ public override bool Equals(object obj)
Copy file name to clipboardExpand all lines: UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -738,19 +738,22 @@ int CompareTo(AmplitudeRatio other)
738
738
returnleft._decibelVolts>right._decibelVolts;
739
739
}
740
740
741
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
// ReSharper disable once CompareOfFloatsByEqualityOperator
744
745
returnleft._decibelVolts==right._decibelVolts;
745
746
}
746
747
748
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
// ReSharper disable once CompareOfFloatsByEqualityOperator
750
752
returnleft._decibelVolts!=right._decibelVolts;
751
753
}
752
754
#endif
753
755
756
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
754
757
publicoverrideboolEquals(objectobj)
755
758
{
756
759
if(obj==null||GetType()!=obj.GetType())
@@ -761,6 +764,19 @@ public override bool Equals(object obj)
Copy file name to clipboardExpand all lines: UnitsNet/GeneratedCode/Quantities/Angle.g.cs
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1720,19 +1720,22 @@ int CompareTo(Angle other)
1720
1720
returnleft._degrees>right._degrees;
1721
1721
}
1722
1722
1723
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1723
1724
publicstaticbooloperator==(Angleleft,Angleright)
1724
1725
{
1725
1726
// ReSharper disable once CompareOfFloatsByEqualityOperator
1726
1727
returnleft._degrees==right._degrees;
1727
1728
}
1728
1729
1730
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1729
1731
publicstaticbooloperator!=(Angleleft,Angleright)
1730
1732
{
1731
1733
// ReSharper disable once CompareOfFloatsByEqualityOperator
1732
1734
returnleft._degrees!=right._degrees;
1733
1735
}
1734
1736
#endif
1735
1737
1738
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1736
1739
publicoverrideboolEquals(objectobj)
1737
1740
{
1738
1741
if(obj==null||GetType()!=obj.GetType())
@@ -1743,6 +1746,19 @@ public override bool Equals(object obj)
1743
1746
return_degrees.Equals(((Angle)obj)._degrees);
1744
1747
}
1745
1748
1749
+
/// <summary>
1750
+
/// Compare equality to another Angle by specifying a max allowed difference.
1751
+
/// Note that it is advised against specifying zero difference, due to the nature
1752
+
/// of floating point operations and using System.Double internally.
1753
+
/// </summary>
1754
+
/// <param name="other">Other quantity to compare to.</param>
Copy file name to clipboardExpand all lines: UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -620,19 +620,22 @@ int CompareTo(ApparentPower other)
620
620
returnleft._voltamperes>right._voltamperes;
621
621
}
622
622
623
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
// ReSharper disable once CompareOfFloatsByEqualityOperator
626
627
returnleft._voltamperes==right._voltamperes;
627
628
}
628
629
630
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
// ReSharper disable once CompareOfFloatsByEqualityOperator
632
634
returnleft._voltamperes!=right._voltamperes;
633
635
}
634
636
#endif
635
637
638
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
636
639
publicoverrideboolEquals(objectobj)
637
640
{
638
641
if(obj==null||GetType()!=obj.GetType())
@@ -643,6 +646,19 @@ public override bool Equals(object obj)
Copy file name to clipboardExpand all lines: UnitsNet/GeneratedCode/Quantities/Area.g.cs
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1610,19 +1610,22 @@ int CompareTo(Area other)
1610
1610
returnleft._squareMeters>right._squareMeters;
1611
1611
}
1612
1612
1613
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1613
1614
publicstaticbooloperator==(Arealeft,Arearight)
1614
1615
{
1615
1616
// ReSharper disable once CompareOfFloatsByEqualityOperator
1616
1617
returnleft._squareMeters==right._squareMeters;
1617
1618
}
1618
1619
1620
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1619
1621
publicstaticbooloperator!=(Arealeft,Arearight)
1620
1622
{
1621
1623
// ReSharper disable once CompareOfFloatsByEqualityOperator
1622
1624
returnleft._squareMeters!=right._squareMeters;
1623
1625
}
1624
1626
#endif
1625
1627
1628
+
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
1626
1629
publicoverrideboolEquals(objectobj)
1627
1630
{
1628
1631
if(obj==null||GetType()!=obj.GetType())
@@ -1633,6 +1636,19 @@ public override bool Equals(object obj)
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
966
969
publicoverrideboolEquals(objectobj)
967
970
{
968
971
if(obj==null||GetType()!=obj.GetType())
@@ -973,6 +976,19 @@ public override bool Equals(object obj)
0 commit comments