I am making a simple struct for complex numbers and i want to check they are equal by comparing the components.
Currently i have:
public struct Complex
{
public float Re;
public float Img;
public Complex(float real, float imaginary)
{
Re = real;
Img = imaginary;
}
public static bool operator ==(Complex a, Complex b)
{
return Mathf.Approximately(a.Re - b.Re, 0) && Mathf.Approximately(a.Img - b.Img, 0);
}
public static bool operator !=(Complex a, Complex b) => !(a == b);
}
But i've seen other code where people use IEquatable with the Equals function. Am i suppose to use that here or is my code the correct way to do it? I am a bit unsure when to use the interface and when not to at the moment.