double a, b = ...;
Are the following C#-statements
!(a > b)
and
a <= b
equivalent or are there any numerical caveats?
The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.
C# | Less than or equal to: <= | Easy language reference. C# | Visual C# | .NET. Types and variables. Basic data types.
They are equivalent if they are standard vanilla double numeric values.
With nullable, NaN, etc, this isn't as clear.
Consider
double? a = null;
double b = 1;
if (!(a > b))
{
//yes
}
if ((a <= b))
{
//no
}
Or as Marc Gravell♦ pointed out, the below demonstrates the exact same behaviour, while sticking with pure double
:
double a = 42;
double b = double.NaN;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With